Angular 2-绑定不能包含分配 [英] Angular 2 - Bindings cannot contain assignments

查看:87
本文介绍了Angular 2-绑定不能包含分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果item的属性与数组中对象的属性具有相同的值,我需要给<tr>一个类.

I need to give a class to a <tr> if a property of item has the same value as a property from an object in an array.

这是我目前拥有的代码:

<tr *ngFor="let item of closingDayGroupsList" [class.inactive]="definitionDetails.Groups.filter(i => i.AbsenceReservationGroupID === item.ID).length > 0">

但是现在我收到了错误:

Bindings cannot contain assignments

我不确定我在做什么是错误的做法,还是只是在犯语法错误.

I'm not sure if what I'm doing is bad practice, or if I'm just making syntax errors.

这是我知道实现自己想要的唯一方法,但是它不起作用

This is the only way I know to achieve what I want, but it's not working

推荐答案

angular bindings

class 表达式移动到控制器中.

export class AppComponent {
    title = 'Groups';

    getClass(item): void {

      // add filter logic here
      return this.definitionDetails.Groups.filter(i => i.AbsenceReservationGroupID === item.ID).length > 0

    }
}

tr将会是类似的

<tr *ngFor="let item of closingDayGroupsList" [class.inactive]="getClass(item)">

这篇关于Angular 2-绑定不能包含分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆