【问题标题】:Angularjs: ng-repeat + ng-switch-when != expectedAngularjs:ng-repeat + ng-switch-when != 预期
【发布时间】:2013-06-30 19:01:18
【问题描述】:

以下代码似乎无法正常工作:

<div ng-switch on="current">
    <div ng-repeat="solution in solutions" ng-switch-when="{{solution.title}}">
        {{solution.content}}
    </div>
</div>

{{solution.title}} 的输出实际上是{{solution.title}}。它不会被 angular 处理。

【问题讨论】:

    标签: angularjs angularjs-ng-repeat ng-switch


    【解决方案1】:

    ng-switch-when 标签需要一个常量,你不能在里面放一个变量。 您可以按如下方式修改您的代码:

    <div ng-repeat="solution in solutions">
        <div ng-show="current == solution">
            {{solution.content}}
        </div>
    </div>
    

    【讨论】:

    • 嘿,雷米吉奥。感谢您的回答,但这并没有削减它。这实际上是我尝试的第一件事。 solution.title 也不会被 angular 处理。
    • 是的,这确实有效!但是我看不出我的版本是怎么错的?!
    • ng-switch-when 不能是变量,必须是常量
    • 也许可以试试 {{ current == solutions }}
    猜你喜欢
    • 2014-06-23
    • 2013-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-03
    • 2014-05-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多