Angular 2 - bindings cannot contain assignments

I need to give a class <tr>

if a property of an element has the same value as a property from an object in an array.

Here's the code I have:

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

      

however now I am getting the error :

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 to know what I want, but it doesn't work

+18


source to share


2 answers


Bad use practice expressions

inangular bindings

Move expression class

into the 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 value will be something like this

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

      

+32


source


There is a small problem with this. Take as an example that I want to stop showing the user a date of 0000.00.00, so by taking the inline expression binding, I can find this correctly:



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

Run code


+1


source







All Articles