Angular 2 - *ngFor 有条件 class

Angular 2 - *ngFor with conditional class

我正在使用 Angular2 和 bootstrap 作为组件。 如果来自 *ngFor 循环的测试的 属性“2”等于名为 newTest 的导入变量,我将尝试向我的 tr-tag 添加一个 class。 但它没有添加 class。

这是我的组件:

loadTest() {
      this.testService.getTests()
         .then((data) => {
            this.tests = data
         })
   }

ngOnInit() {
      this.loadTest();
   }

table 显示正确,但 class 不存在。

不过条件确实满足了。

这是我的 html:

<div class="table-responsive">
    <table class="table table-hover table-reflow">
        <thead>
            <tr>
                <th>1</th>
                <th>2</th>
                <th>3</th>
                <th>4</th>
                <th>5</th>
            </tr>
        </thead>
        <tbody>
            <tr *ngFor="let test of tests" [class.newDevice]="test.2 === this.newTest" [attr.class]="test.1" >
                <th>{{test.1}}</th>
                <th>{{test.2}}</th>
                <th>{{test.3}}</th>
                <th>{{test.4}}</th>
                <th>{{test.5}}</th>
            </tr>
        </tbody>
    </table>
</div>

我是不是做错了什么? 我也尝试用 jquery 实现同样的效果:

    loadTest() {
          this.testService.getTests()
             .then((data) => {
                this.tests = data
    if (NewTest.length !== undefined) {
                   let index = this.tests.findIndex((e) => { return e.2 === NewTest })
                   let test = this.tests[index].id
                   jQuery(test).addClass("newDevice");
                }
           })
       )

[class.newDevice][attr.class] 相互覆盖。