Skip to main content

Posts

Showing posts from April 6, 2021

Angular *ngIf & else | Angular Tips

    Normally We will use the   *ngIf to show hide the controls by using following method             <div  *ngIf="showIf" >               <p>                 Showing the if part               </p>             </div> Where showIf needs to be declared in the component.ts file and it needs to be set as true in order to view that control   Like this showIf : Boolean;   in the constructor or in the ngIf   this. showIf – true;   For Else we need to create a ng-template and call in the else part like below   Please Note: the ng-template’s id should be unique   <div *ngIf="showIf; else  elsePart">   <p      Showing the if part   </p> </div>       <ng-template #elsePart>     <p>     Showing the else part   </p>  </ng-template>     Example Source can be found at : https://angular-ivy-5vysbz.stackblitz.io