Angular 表定义上的ng类未解析

Angular 表定义上的ng类未解析,angular,html-table,ng-class,Angular,Html Table,Ng Class,角度4应用: 我有一个模型列表,通过它我可以使用*ngFor创建一些表行。每个模型都有一个包含一些字符串的列表: { ..., changes: [ 'Test1', 'Test2' ] } 示例表和*ngFor如下所示: <table> <tr> <th>...</th> ... </tr> <tr *ngFor="let item of list

角度4应用:

我有一个模型列表,通过它我可以使用*ngFor创建一些表行。每个模型都有一个包含一些字符串的列表:

{
  ...,
  changes:
  [
    'Test1',
    'Test2'
  ]
} 
示例表和*ngFor如下所示:

<table>
   <tr>
     <th>...</th>
         ...
   </tr>
   <tr *ngFor="let item of list">
        <td ng-class="'cell-changed' : item.changes.indexOf('Test1') !== -1"> 
          {{item?.test1}}</td>
        <td ng-class="'cell-changed' : item.changes.indexOf('Test5') !== -1"> 
          {{item?.test2}}</td>

   </tr>
</table>

虽然这没有抛出错误,但它也不起作用。我错过了什么?

你在混合AngularJS和AngularApproach。如果您使用的是Angular 2+,则应使用
[ngClass]
,例如:

<td [ngClass]="{'cell-changed': item.changes.indexOf('Test5') !== -1}"> 
    {{item?.test2}}
</td>

{{item?.test2}}

ng类
在Angular中不存在。这是AngularJS指令

最干净的方法是这样做:

[class.cell-changed]="item.changes.indexOf('Test1') !== -1"

谢谢你的澄清和帮助。这工作做得很好!泰
<td [ngClass]="{'cell-changed': item.changes.indexOf('Test5') !== -1}"> 
    {{item?.test2}}
</td>
[class.cell-changed]="item.changes.indexOf('Test1') !== -1"