如何在Angular中使用布尔模型属性切换类?

Ger*_*rit -1 javascript angularjs

我试过这个:

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

但后来我收到了一个错误:

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

Epo*_*okK 6

使用ng-class这样:

<li ng-repeat="todo in todos" ng-class="{ 'test' : todo.isCompleted }">
Run Code Online (Sandbox Code Playgroud)

参考