1

So I have a dynamic table in angular where im passing data in, then creating the table. I want to add some CSS in order to check the values then add some styling onto it. So if the value is a minus number, then display the data in red

I have used attribute data to check the actual data, which works fine until i call to typescript method to generate the data instead of hardcoding the data in, and this is where is goes wrong. So I want to call this method to get the data instead, and it just displays the method name instead of the method return

2345678
  • 69
  • 7

1 Answers1

1

You can use the attribute binding of data instead of the interpolation if the data returned by the method is not a string - more details here

[attr.data]="getData(header, body)"
edkeveked
  • 17,989
  • 10
  • 55
  • 93
  • I removed the interpolation of the method, and it still displays as the method call instead of the data returned. When I added [] around the data I got an error stating Can't bind to 'data' since it isn't a known property of 'td'. – 2345678 Aug 13 '19 at 14:45
  • I edited the answer. But still, can you add the code of `getData` ? – edkeveked Aug 13 '19 at 14:50
  • Hey man! thank you so much that has worked now! Have you got a link to learn more about data attributes where you found that or is it just your experience and knowledge? – 2345678 Aug 13 '19 at 14:55
  • https://stackoverflow.com/questions/46064873/how-to-bind-to-a-data-attribute-using-angular-2 – edkeveked Aug 13 '19 at 14:56