我得到一個響應從服務器到一個JSON(包含color.mix和color.pure)並直接傳遞給模板,所以,在這個模板中,我需要知道的值,從而來顯示它或顯示其他值檢查是否爲一個值,如果不顯示另一個東西
<span ng-if="color.mix">{{color.mix}}</span>
但是,如果該值不來,我需要表現出「純粹」價值,所以我做了(錯!!)
<span ng-if="!color.mix">{{color.pure}}</span>
<span ng-if="color.mix">{{color.mix}}</span>
但是,當兩者都來了,都被顯示。
我該如何實現這個目標?
(角1.6)
一個'NG-else'的想法已經扔了,現在繞了一段時間,但據我知道沒有什麼是官方的。不過,你可能對'ng-switch'感興趣。因爲它符合你的標準。 https://docs.angularjs.org/api/ng/directive/ngSwitch – mhodges