Angular 2 - Bindings cannot contain assignments

后端 未结 2 709
迷失自我
迷失自我 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 00:58

    There is a little problem with that. Take as an example, that I want to stop showing the date to the user which is equal to 0000.00.00, so, by taking the inline expression binding I can find it right to:

     {{(appointment_date === "0000.00.00") ? ' ' : appointment_date}} 

    0 讨论(0)
  • 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,

    <tr *ngFor="let item of closingDayGroupsList" [class.inactive]="getClass(item)">
    
    0 讨论(0)
提交回复
热议问题