简体   繁体   中英

Angular ngClass not working

I'm new to Angular and I'm trying to get ngClass to work but it doesn't want to. Here is my code:

<div *ngFor= "let job of dashboardJobsDetails" class="card">
    <div  ngClass="{'red card':job.status == 'Failed', 'yellow card': 
          job.status =='Warning', 'green card': job.status =='Success'}">
        Status: {{job.status}}
    </div>
</div>

The ngFor works great, the second div shows the correct status, but the ngClass never applies the style. Any ideas or tips?

The syntax is wrong, it should be

<div  [ngClass]="{'red card':job.status == 'Failed', 'yellow card': 
      job.status =='Warning', 'green card': job.status =='Success'}">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM