[ERROR] NG5002: Parser Error: Bindings cannot contain assignments




Asked on May 14, 2024
In <mat-icon> element, I am assigning icon name using find() method.

<mat-icon>{{allEmps.find(e => e.name === this.selectedEmpAsArray?.[0]).icon}}</mat-icon>

But I am getting error.

[ERROR] NG5002: Parser Error: Bindings cannot contain assignments at column
 in [{{allEmps.find(e => e.name === this.selectedEmpAsArray?.[0]).icon}}] 



Replied on May 14, 2024
Angular does not recommend assignment in binding. You should use it inside TS file.

TS code:

selectedEmpIcon = '';
onChange() {
  this.selectedEmpIcon = this.allEmps.find(e => e.name === this.selectedEmpAsArray?.[0])?.icon ?? '';
}

HTML code:

{{selectedEmpIcon}}



Replied on May 14, 2024
Working. Thanks.

Write Answer












©2024 concretepage.com | Privacy Policy | Contact Us