ng-repeat th元素删除属性

时间:2017-01-04 12:58:54

标签: javascript angularjs ng-repeat

所以我有以下ng-repeat

<th ng-repeat="field in tableFields" translate="{{field.headerTitle | translate}}"
    ts-criteria="{{field.sortable ? field.fieldKey : null}}">
    <label class="i-checks" ng-if="field.isCheckbox">
        <input type="checkbox" ng-model="checkAll" ng-change="selectAll(checkAll)">
        <i></i>
    </label>
</th>

这样可以正常工作但是由于外部脚本中的一些错误,如果ts-criteria,则不应设置field.fieldKey is null。所以我的问题是如何完全删除属性?

1 个答案:

答案 0 :(得分:2)

如果认为一个好的选择是使用ng-switch来选择是否应该设置您的属性。

没有完整的代码,但它会是这样的:

<div ng-switch on="myVar">
    <th ng-switch-when="true" ts-criteria>ts-criteria here</th>
    <th ng-switch-default>not here</th>
</div>

Here is a demo on JSFiddle

通过更改myVar来尝试。

相关问题