简体   繁体   English

Angular 2无法绑定到'ngif',因为它不是已知属性

[英]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.

相关问题 Angular 6 无法绑定到“*ngIf”,因为它不是已知属性 - Angular 6 Can't bind to '*ngIf' since it isn't a known property 无法绑定到“ngif”,因为它不是“span”的已知属性 - Can't bind to 'ngif' since it isn't a known property of 'span' 无法绑定到“ngIf”,因为它不是“form”的已知属性 - Can't bind to 'ngIf' since it isn't a known property of 'form' 无法绑定到“ngIf”,因为它不是“表”的已知属性 - Can't bind to 'ngIf' since it isn't a known property of 'table' Angular Karma Jasmine 测试“无法绑定到 &#39;ngIf&#39;,因为它不是已知属性” - Angular Karma Jasmine test “Can't bind to 'ngIf' since it isn't a known property” 在控制台中出现错误无法绑定到“ngif”,因为它不是 angular 应用程序中“div”的已知属性 - Getting error in console Can't bind to 'ngif' since it isn't a known property of 'div' in angular app NX / Angular IntelliSense 的 VSCode IntelliSense 错误“无法绑定到 'ngIf',因为它不是 'div' 的已知属性” - VSCode IntelliSense error with NX / Angular IntelliSense "Can't bind to 'ngIf' since it isn't a known property of 'div'" angular 2 控制台错误无法绑定到“ngIf”,因为它不是“span”的已知属性 - angular 2 console error Can't bind to 'ngIf' since it isn't a known property of 'span' Angular 抛出错误:无法绑定到“ngIf”,因为它不是“ng-container”的已知属性 - Angular throws error: can't bind to “ngIf” since it isn't a known property of “ng-container” 无法绑定到“ngIf”,因为它不是“div”的已知属性 - 离子/角度错误 - Can't bind to 'ngIf' since it isn't a known property of 'div' - ionic/angular error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM