0

I want to apply this directive inside td cells, there are 6 columns and i want to apply only at the columns 1,2,3 and 5.

Is there a cleaner way to apply instead of applying raw html tags to these four cells ?

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

I end with a 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 ......
3
  • 4
    You should move this logic to the controller, as a method, will make the view cleaner Commented Jul 14, 2015 at 18:13
  • 1
    will you please share more code please ? Commented Jul 14, 2015 at 18:14
  • 1
    please don't dump code into comments... update the actual question where the code can be formatted and readable and people don't have to sift through comments when reading the question Commented Jul 14, 2015 at 18:22

1 Answer 1

2

I agree w/ the comment from @Fals that this logic can/should be in the controller but to make it more concise you can do something like this:

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

UPDATE per request of Ângelo Rigo:

To do this in the controller:

markup: //ctrlRef is reference to the controller (assuming controllerAs)
<span ng-if="ctrlRef.showItem(item)">$ </span>

// in the controller (ES5):
this.showItem = function(item){
  return [2,7,10,11].indexOf(item.index) >= 0;
}

// in the controller (ES6/TypeScript)
showItem(item) {
  return [2,7,10,11].indexOf(item.index) >= 0;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Brocco it is working, how would it written in a controller method ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.