htmlangularangular-ng-ifangular-template

Angular, ng-templates with if condition


I want to call for two separate templates according to role id changes. I can get my role which role as

ngIf="rolet.role.id== adminRoleId

two templates are,

<ng-template #role ></ng-template>

and

<ng-template #admin ></ng-template>

Solution

  • I really don't know how many role in your project. But if you want to use two ng-template,check and test with the following code.

    <div *ngIf="ngIf="rolet.role.id== adminRoleId; then #role else #admin"></div>
    <ng-template #role>
      ...
    </ng-template>
    <ng-template #admin>
      ....
    </ng-template>