如何用ng-if选择课程

时间:2014-12-31 10:50:13

标签: javascript angularjs

我有ng-repeat

HTML:

<td class="border" data-ng-repeat="price in goHead.prices track by $index">

在我的<td> data-ng-if="price.isMinPrice"选择class="border else data-ng-if="! price.isMinPrice",选择class="noBorder"

是否可以在AngularJS中执行此操作?

4 个答案:

答案 0 :(得分:2)

是的可能(您可以使用ng-class):

<td ng-repeat="price in goHead.prices track by $index" ng-class="{border: price.isMinPrice, noBorder: !price.isMinPrice}">
</td>

或者你可以写:

<td ng-repeat="price in goHead.prices track by $index" class="{{price.isMinPrice ? 'border' : 'noBorder'}}">
</td>

答案 1 :(得分:1)

您可以使用AngularJs ngClass

<td 
 data-ng-repeat="price in goHead.prices track by $index"
 data-ng-class="{border: price.isMinPrice, noBorder: !price.isMinPrice}">
...
</td>

答案 2 :(得分:1)

查看ng-class

<td class="border"
    data-ng-repeat="price in goHead.prices track by $index"
    ng-class="{border: price.isMinPrice, noBorder: !price.isMinPrice}"
    >
</td>

答案 3 :(得分:1)

使用angularjs提供的ngClass指令。 ngClass指令允许您通过数据绑定表示要添加的所有类的表达式,在HTML元素上动态设置CSS类。 例如:

...
<p ng-class="{strike: deleted, bold: important}">Map Syntax Example</p>
<input type="checkbox" ng-model="deleted"> deleted (apply "strike" class)<br>
<input type="checkbox" ng-model="important"> important (apply "bold" class)<br>
...

试试这个,会对你有帮助。