[英]Angular 2 Can't bind to 'ngif' since it isn't a known property
I am experimenting with Angular 2. I have a working test app with two components. 我正在试验Angular 2.我有一个有两个组件的工作测试应用程序。 It all works, but it crashes when I try to use
*ngif
一切正常,但是当我尝试使用
*ngif
时崩溃了
There are already a lot of questions about this problem but most of the answers point to importing "BrowserModule" to fix the problem. 关于这个问题已经有很多问题,但大多数答案都指向导入“BrowserModule”来解决问题。 In my case, I already do that.
就我而言,我已经这样做了。 What else could be causing this problem?
还有什么可能导致这个问题?
my html 我的HTML
<table class='table' *ngif="products && products.length">
app.module.ts app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { CrazyComponent } from './products/crazy.component';
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent, CrazyComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
The full error: 完整的错误:
Can't bind to 'ngif' since it isn't a known property of 'table'. 无法绑定到'ngif',因为它不是'table'的已知属性。 Property binding ngif not used by any directive on an embedded template.
嵌入式模板上的任何指令都未使用的属性绑定ngif。 Make sure that the property name is spelled correctly and all directives are listed in the "directives" section
确保属性名称拼写正确,并且所有指令都列在“指令”部分中
You have a typo. 你有一个错字。 Use
ngIf
instead of ngif
使用
ngIf
而不是ngif
Correct way to use it: 正确的使用方法:
<table class='table' *ngIf="products && products.length">
UPDATE : 更新 :
Many people (including me) got this issue, because IntelliJ IDEA/WebStorm autocompletion gives invalid ngif
. 许多人(包括我)都遇到了这个问题,因为IntelliJ IDEA / WebStorm自动完成功能会产生无效的
ngif
。 Additionally, IDEA highlights *ngIf
as invalid. 此外,IDEA强调
*ngIf
无效。
Recently I upgraded my IDEA to 2017.2.5 together with JS/Angular plugins and this problem is gone. 最近我将我的IDEA与JS / Angular插件一起升级到了2017.2.5,这个问题就消失了。 Also, I got better NG2+ autocompletion and better TypeScript support.
此外,我有更好的NG2 +自动完成和更好的TypeScript支持。 This is why I highly recommend upgrading JetBrains software.
这就是我强烈建议升级JetBrains软件的原因。
you have an error because of "*ngif" correct one is "*ngIf". 你有一个错误,因为“* ngif”正确的是“* ngIf”。 The capital 'I' here and the capital 'F' in *ngFor..I used to mistype a lot of times.
这里的首都'我'和* ngFor..I中的首都'F'曾多次输错。 Just be a little patient.
只是有点耐心。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.