zoukankan      html  css  js  c++  java
  • ng-repeat 嵌套 ng-switch 出错解决

    Error: $compile:ctreq

    Missing Required Controller
    Controller 'ngSwitch', required by directive 'ngSwitchWhen', can't be found!


    <div class="item" ng-repeat="item in list">
    <!--0表进行中,1表已提车, 2表待结账-->
    <div ng-switch="item.state.value">
          <div ng-switch-when="0" class="ui top right attached label yellow">服务中</div>
      <div ng-switch-when="1" class="ui top right attached label red">已结账</div>
      <div ng-switch-when="2" class="ui top right attached label orange">待结账</div>
      <div ng-switch-default class="ui top right attached label">已挂账</div>
    </div>
    </div>

    ng-repeat每个循环都会创建一个scope

    修改为:

    <div class="item" ng-repeat="item in list" ng-switch="item.state.value">
    <!--0表进行中,1表已提车, 2表待结账-->

    <div ng-switch-when="0" class="ui top right attached label yellow">服务中</div>
    <div ng-switch-when="1" class="ui top right attached label red">已结账</div>
    <div ng-switch-when="2" class="ui top right attached label orange">待结账</div>
    <div ng-switch-default class="ui top right attached label">已挂账</div>
    </div>
     

    AngularJS ng-repeat下使用ng-model

    <table>
    <tr ng-repeat="row in collections">
    <td>
    {{row.name}}: <input type="radio" value="{{row.value}}" ng-model="selectValue"/>
    </td>
    </tr>
    </table>

    当你书写了上述代码后。你会发现点击其中的对话框,$scope.selectValue中并没有保存你选中的对应单选框的值。

    这是因为处在ng-repeat之间的代码,对全局的$scope里变量的内容是不可见的,而是为ng-repeat创建的子scope里面的。

    所以要引用ng-repeat $scope里的成员,你可以使用$parent

     
    <table>
    <tr ng-repeat="row in collections">
    <td>
    {{row.name}}: <input type="radio" value="{{row.value}}" ng-model="$parent.selectValue"/>
    </td>
    </tr>
    </table>
     
  • 相关阅读:
    《剑指offer》第三十五题(复杂链表的复制)
    《剑指offer》第三十四题(二叉树中和为某一值的路径)
    分支限界法
    回溯法小实例
    BUFSIZ解析
    ofstream和ifstream详细用法
    回溯法——最大团问题(Maximum Clique Problem, MCP)
    位运算应用之二——大小写转换
    回溯法——n后问题
    回溯法——批处理作业调度
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/5243771.html
Copyright © 2011-2022 走看看