Angular ngClass不起作用

时间:2017-09-01 20:08:34

标签: html angular ng-class

我是Angular的新手,我正在努力让ngClass工作,但它不想这样做。 这是我的代码:

<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>

ngFor工作得很好,第二个div显示正确的状态,但ngClass从不应用该样式。任何想法或提示?

1 个答案:

答案 0 :(得分:3)

语法错误,应该是

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