Home > Enterprise >  Angular, ng-templates with if condition
Angular, ng-templates with if condition

Time:01-16

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>

CodePudding user response:

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>
  • Related