I keep getting the error
Can't bind to 'ngIfElse' since it isn't a known property of 'ul'.
I'm sure somewhere I am making a stupid mistake but can't find it.
<ul *ngIf="!finished; else elseBlock" id='time'>
<li id='hour' class="chart" data-percent="100"><span>{{hour}} </span></li>
<li id='min' class="chart" data-percent="100"><span>{{minute}}</span></li>
<li id='second' class="chart" data-percent="100"><span>{{second}}</span></li>
</ul>
<ng-template #elseBlock> <h4 id='time'>DONE</h4> </ng-template>
We can use multiple conditions in *ngIf with logical operator AND (&&) to decide the trustworthy of *ngIf expression. If all conditions are true, then element will be added to the DOM.
Angular 2 does not support Esle, you have 2 options:
1: using positive case:
<ul *ngIf="!finished" id="time">
<li id='hour' class="chart" data-percent="100"><span>{{hour}} </span></li>
<li id='min' class="chart" data-percent="100"><span>{{minute}}</span></li>
<li id='second' class="chart" data-percent="100"><span>{{second}}</span</li>
</ul>
<h4 id="time" *ngIf="finished"> <!-- this -->
DONE
</h4>
2: update your app to Angular 4:
On Linux/Mac:
npm install @angular/{common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router,animations}@latest typescript@latest --save
On Windows:
npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript@latest --save
If you rely on Animations, import the new BrowserAnimationsModule from @angular/platform-browser/animations in your root NgModule. Without this, your code will compile and run, but animations will trigger an error. Imports from @angular/core were deprecated, use imports from the new package import { trigger, state, style, transition, animate } from '@angular/animations';.
http://angularjs.blogspot.com/2017/03/angular-400-now-available.html
The ng-if
directive only handles the positive case. For the negative case (the else
) use a separate block:
<ul ng-if="!finished" id="time">
<li id='hour' class="chart" data-percent="100"><span>{{hour}} </span></li>
<li id='min' class="chart" data-percent="100"><span>{{minute}}</span></li>
<li id='second' class="chart" data-percent="100"><span>{{second}}</span></li>
</ul>
<ng-if="finished">
<h4 id='time'>DONE</h4>
</ng-template>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With