问题
<h3 style="color:#00bfff;margin:-14px 0 16px 0px" class="inline" *ng-if="data.for == 'next'">
{{data.bannerText}}<sup><small>{{data.super}}</small></sup>
</h3>
<span class="NotinStockGrey"> {{data.textOne}} </span>
<span style="color:#00bfff"> {{data.textTWo}} </span>
error:
zone.js:420 Unhandled Promise rejection: Template parse errors: Can't bind to 'ng-if' since it isn't a known property of 'h3'. ("0Fb;margin:-16px 0 16px 0px">
回答1:
It's
*ngIf="..."
(not ng-if)
https://angular.io/docs/ts/latest/api/common/index/NgIf-directive.html
You also need to add BrowserModule (AppModule) or CommonModule to imports: [] of @NgModule(...) to make it available for the components of a module.
回答2:
You have to use *ngIf instead of *ng-if.
<h3 style="color:#00bfff;margin:-14px 0 16px 0px" class="inline" *ngIf="data.for == 'next'">{{data.bannerText}}<sup><small>{{data.super}}</small></sup></h3><span class="NotinStockGrey" > {{data.textOne}} </span><span style="color:#00bfff">{{data.textTWo}}</span>
回答3:
The attribute ng-if is changed in Angular2+, so simply use *ngIf="whatever"
Something like below:
<div *ngIf="userObservable | async as user; else loading">
Hello {{user.last}}, {{user.first}}!
</div>
Or something like this:
<div *ngIf="mate">
Hello {{ mate }}!
</div>
来源:https://stackoverflow.com/questions/42582411/how-to-ng-if-in-angular-2