Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  9] [ 4]  / answers: 1 / hits: 47038  / 7 Years ago, thu, march 30, 2017, 12:00:00

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.



Here's the code I currently have:



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


however now I receive 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 I know to achieve what I want, but it's not working


More From » angular

 Answers
51

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)>

[#58328] Tuesday, March 28, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aliah

Total Points: 118
Total Questions: 132
Total Answers: 94

Location: Tajikistan
Member since Fri, Sep 11, 2020
4 Years ago
;