Search code examples
angularangular-materialangular-ng-if

How can I set multiple conditions on the same *ngIf within a tag?


I have a form with multiple fields in angular material. In a field I need to establish the condition that if the user is "admin" it occupies 2 columns of the table, if not, it occupies 3 columns.

This is my current code:

<mat-grid-tile [colspan]="3">
     <div fxFlex>
          <date fxFlex title="Fecha inicio" [monthInput]="true" formControlName="date"></date>
     </div>
</mat-grid-tile>

This is the code that I am testing but I can't get it to work:

<mat-grid-tile *ngIf="is_admin; then [colspan]="2"; else [colspan]="3"">
     <div fxFlex>
          <date fxFlex title="Fecha inicio" [monthInput]="true" formControlName="date"></date>
     </div>
</mat-grid-tile>

How can I set the condition inside the label to get it to fit the columns?


Solution

  • [colspan]="is_admin ? 2 : 3"