如何在angular 2中ng-if [英] How to ng-if in angular 2

查看:64
本文介绍了如何在angular 2中ng-if的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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>

错误:

zone.js:420未处理的承诺拒绝:模板解析错误:无法绑定到"ng-if",因为它不是"h3"的已知属性.("0Fb; margin:-16px 0 16px 0px">

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">

推荐答案

*ngIf="..."

(不是 ng-if )

https://angular.io/docs/ts/latest/api/common/index/NgIf-directive.html

您还需要将 BrowserModule ( AppModule )或 CommonModule 添加到 imports:[code] of> @NgModule(...)使其可用于模块的组件.

You also need to add BrowserModule (AppModule) or CommonModule to imports: [] of @NgModule(...) to make it available for the components of a module.

这篇关于如何在angular 2中ng-if的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆