ng 开关无法按预期工作



与其有两个单独的ng-if,我想将它们组合起来并使用ng-switch。但是,img()函数未按预期切换。我应该采取哪些不同的做法?

把这个:

<img ng-src="{{img(myColor)}}" ng-if="myColor">
<img ng-src="{{img(myColor2)}}" ng-if="myColor2">

进入这个:

<div ng-switch on = "myColor2">
    <div ng-switch-when = "myColor2">
        <img ng-src="{{img(myColor2)}}">
    </div>
    <div ng-switch-default = "myColor">
        <img ng-src="{{img(myColor)}}">
    </div>
</div>

下面是一个 ng-switch 的例子

http://jsfiddle.net/fbg3bLac/5/

你可能理解错了。

ng-switch on = "myColor2" -- means you want to evaluate the value of the scope variable myColor2.
ng-switch-when = "myColor2" -- states that if the VALUE of myColor2 is equal to 'myColor2' then do this.
ng-switch-default -- should have no = value.

请参考 http://www.c-sharpcorner.com/UploadFile/75a48f/switch-condition-in-angularjs/

相关内容

  • 没有找到相关文章

最新更新