如何在 Angular 2 中使用“ng-if" [英] How to use 'ng-if' in Angular 2

查看:27
本文介绍了如何在 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;边距:-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:

*ngIf="..."

(不是ng-if)

您还需要将 BrowserModule (AppModule) 或 CommonModule 添加到 imports: []>@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天全站免登陆