ng-repeat 嵌套 ng-switch 出错解决

Posted 风来了

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>
 

以上是关于ng-repeat 嵌套 ng-switch 出错解决的主要内容,如果未能解决你的问题,请参考以下文章

嵌套 ng-repeat 拖放,AngularJS

在嵌套的 ng-repeat 中传递 2 个 $index 值

嵌套 ng-repeat 的 AngularJS 记录计数

角度过滤器,嵌套 ng-repeat

提高嵌套 ng-repeat + 指令的性能

为啥 ng-click 需要通过 $index 跟踪才能在嵌套的 ng-repeat 内触发