Angular *ngIf-else with ng-template

Last Updated on

This post briefly demonstrates how to create an if-else construct in HTML using *ngIf and ng-template.

Tested On

  • Angular 8
  • Nodejs 10+

Component Codes

Initially, we set serverName to '' and use $event to get the value from as the user types in the values.

HTML Codes

We use the (input) event with onUpdateServerName($event) . The if-else part is on line 2 but with the display for else referring to an ng-template element.


Karl San Gabriel

Karl San Gabriel

Professional Software Developer