【问题标题】:Using Ternary Operator Inside ng-repeat Directive在 ng-repeat 指令中使用三元运算符
【发布时间】:2020-12-29 02:45:13
【问题描述】:

可以在ng-repeat 指令中使用三元运算符吗?例如,在某些情况下,我想加载一个列表而不是另一个,这取决于变量或标志的值:

ng-repeat="$ctrl.darkMode == true ? item in $ctrl.darkList : item in $ctrl.normalList

提前谢谢...

【问题讨论】:

    标签: angularjs angularjs-directive conditional-operator


    【解决方案1】:

    这样不行,但你可以这样做:

    ng-repeat="item in ($ctrl.darkMode == true ? $ctrl.darkList : $ctrl.normalList)"
    

    如果你的情况变得复杂,你总是可以使用方法:

    ng-repeat="item in $ctrl.getList()"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-20
      • 2022-09-30
      • 1970-01-01
      • 2013-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多