Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个像这样的 ng-class
ng-class="{'alert alert-success': response.submitSuccess , 'alert alert-danger': !response.submitSuccess }"
问题是,假设“response.submitSuccess”返回 true ,只添加了 alert-success 类而不是 alert 类。
那么让alert课程永久化不是更有意义吗?(反问)
alert
你可以这样做:
class="alert" ng-class="{'alert-success': response.submitSuccess , 'alert-danger': !response.submitSuccess}"
这就是行为的原因(它删除了alert之前由!response.submitSuccess条件设置的类,因为它之前是虚假的):
!response.submitSuccess
当表达式更改时,先前添加的类被删除,然后才添加新类。
来自:http ://docs.angularjs.org/api/ng/directive/ngClass