Error: Can't have multiple template bindings on one element.

Forums AngularError: Can't have multiple template bindings on one element.
Staff asked 2 years ago

Answers (1)

Add Answer
Shahjaha Shaikh Marked As Accepted
Staff answered 2 years ago

You can not use two template binding on one element in Angular.
For example: If you use *ngIf in the <div> then you can not use *ngFor for the same <div> tag.
But you can achieve the same scenario by wrapping the element in other <div> or in another tag. It is good practice to use <ng-container> because it is a logical container.

 

<ng-container *ngIf="employee">
  <div *ngFor="let emp of employee">
    {{emp.name}}
  </div>
</ng-container>

 

Subscribe

Select Categories