Answers for "display element with ng-template"

0

display element with ng-template

<!-- How to display one element with ng-template (also applies to one or more elements) -->

<div class="button-group">
  <ng-template [ngIf]="tableSettings.selection.selected.length > 0">
        <button mat-button
          class="mat-button"
          (click)="callMethod()">
          Chop Fruit
        </button>
      </ng-template>
   <button mat-button>Some other element</button>
</div>

<!-- The below will NOT work: -->
<!-- ngIf must be in ng-template in order to work properly -->

<div class="button-group">
  <ng-template>
        <button mat-button
          *ngIf="tableSettings.selection.selected.length > 0"
          class="mat-button"
          (click)="callMethod()">
          Chop Fruit
        </button>
      </ng-template>
   <button mat-button>Some other element</button>
</div>
Posted by: Guest on March-07-2022

Browse Popular Code Answers by Language