Marc Rasmussen
Marc Rasmussen

Reputation: 20555

ng-repeat th element remove attribute

So i have the following 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>

This works fine however due to some errors in an external script the ts-criteria should not be set if field.fieldKey is null. So my question is how can i remove the attribute completely?

Upvotes: 0

Views: 77

Answers (1)

Mistalis
Mistalis

Reputation: 18279

If think a good option would be to use ng-switch to choose if your attribute should be set, or not.

Don't have your full code, but it would be something like:

<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

Try it by changing myVar value.

Upvotes: 2

Related Questions