我想要合并它们并使用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>
答案 0 :(得分:0)
Here's an example for ng-switch
http://jsfiddle.net/fbg3bLac/5/
You might be understanding it wrong.
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.
Please refer to http://www.c-sharpcorner.com/UploadFile/75a48f/switch-condition-in-angularjs/