【问题标题】:How to toggle classes with boolean model property in Angular? [duplicate]如何在 Angular 中使用布尔模型属性切换类? [复制]
【发布时间】:2013-07-05 15:28:39
【问题描述】:

我试过了:

<li ng-repeat="todo in todos" class="{{todo.isCompleted ? 'test'}}">
<input type="checkbox" class="toggle"/>
<label>{{todo.text}}</label><button class="destroy"></button>
</li>

然后我得到一个错误:

Error: Lexer Error: Unexpected next character at columns 17-17 [?] in expression [todo.isCompleted ? 'test']

【问题讨论】:

标签: javascript angularjs


【解决方案1】:

像这样使用ng-class

<li ng-repeat="todo in todos" ng-class="{ 'test' : todo.isCompleted }">

Reference

【讨论】:

    【解决方案2】:

    ng-class="{ 'test' : todo.isCompleted }"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-27
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多