0

I've tried some stuff cause I am building a weather dashboard.

I load weather data with http and subscribe, so I'll getting an observable back I cannot go trough like an array in typescript to add new properties.

For example I want to look on each weather data and look if a value has more than 70 °F and tell the weatherdata item to add a new property "weatherdata-sun-hot". Otherwise it should use an other class name "weatherdata-sun-normal" I would use this as a class name to put it in html later with interpolation.

So my idea is to solve this with the html template

So far I do have my code here

<ul>
   <li *ngFor="let item of weatherdata">{{item.dt_txt}} | {{item.main.temp_min}} -> {{item.main.temp_max}}</li>
</ul>

Is there an elegant way to solve this?

Thanks for any help.

user3332010
  • 147
  • 1
  • 11
  • 4
    you need conditional class, see this https://stackoverflow.com/questions/35269179/angular-conditional-class-with-ngclass – Ali Adravi Apr 20 '18 at 20:57
  • @AliAdravi: Thanks for the hint but I cannot see the if/else mechanism there. Like if val greater than something than use classname x otherwhise classname y. Can you give me a quick example? :-) Thanks again. – user3332010 Apr 20 '18 at 21:05
  • @AliAdravi: I've come up with a working solution I tried: `
  • 17 ? 'weather-sun-hot' : 'weather-sun-normal']" >{{item.dt_txt}} | {{item.main.temp_min}} -> {{item.main.temp_max}}
  • ` But for me it's looking like ugly code. Or would you implement it the same way? I am confused. – user3332010 Apr 20 '18 at 21:09