javascript - Angularjs Directives Cleaner code -


i want apply directive inside td cells, there 6 columns , want apply @ columns 1,2,3 , 5.

is there cleaner way apply instead of applying raw html tags these 4 cells ?

 <span ng-if="item.index === 2                                || item.index === 7                               || item.index === 10                               || item.index === 11">$ </span> 

i end huge list of html code :

<td><span ng-if="item.index === 2 || item.index === 7 || item.index === 10 || item.index === 11">$ </span> {{item.label2 | number}}</td> <td><span ng-if="item.index === 2 || item.index === 7 || item.index === 10 || item.index === 11">$ </span> {{item.label3 | number}}</td> <td><span ng-if="item.index === 2 || item.index === 7 ...... 

i agree w/ comment @fals logic can/should in controller make more concise can this:

<span ng-if="[2,7,10,11].indexof(item.index) >= 0">$ </span> 

update per request of Ângelo rigo:

to in controller:

markup: //ctrlref reference controller (assuming controlleras) <span ng-if="ctrlref.showitem(item)">$ </span>  // in controller (es5): this.showitem = function(item){   return [2,7,10,11].indexof(item.index) >= 0; }  // in controller (es6/typescript) showitem(item) {   return [2,7,10,11].indexof(item.index) >= 0; } 

Comments