Angular 2 - Bindings cannot contain assignments

后端 未结 2 700
迷失自我
迷失自我 2020-12-07 00:34

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

Here\'s the code

2条回答
  •  囚心锁ツ
    2020-12-07 01:10

    Its a bad practice to use expressions in angular bindings

    Move the class expression into controller.

    export class AppComponent {
        title = 'Groups';
    
        getClass(item): void {
    
          // add filter logic here
          return this.definitionDetails.Groups.filter(i => i.AbsenceReservationGroupID === item.ID).length > 0
    
        }
    }
    

    The tr will be something like,

    
    

提交回复
热议问题