Angular ng-template Conditional Content Display

Scenario

We have a sayHello:boolean = trueproperty on our AppComponent . When it is set to true Hello should render.

When it is false Goodbye should render.

Approach

<div *ngIf="sayHello else goodbye">
Hello
</div>
<ng-template #goodbye>
Goodbye
</ng-template>

Demo

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ole Ersoy

Ole Ersoy

Founder of Firefly Semantics Corporation