Angular Can';t绑定到';ngIf&x27;因为它不是';t'的已知属性;分区';
Angular Can';t绑定到';ngIf&x27;因为它不是';t'的已知属性;分区';,angular,Angular,无法绑定到“ngIf”,因为它不是“div”的已知属性。 元素是 该组件是: 从“../session/session.service”导入SessionService; 从'@angular/core'导入{Component}; @组成部分({ 提供者:[], 选择器:“导航栏左侧”, 样式:[需要('./navbar left.scss')], 模板:require('./navbar left.html'), }) 导出默认类NavbarLeftComponent{ public isA
无法绑定到“ngIf”,因为它不是“div”的已知属性。
元素是
该组件是:
从“../session/session.service”导入SessionService;
从'@angular/core'导入{Component};
@组成部分({
提供者:[],
选择器:“导航栏左侧”,
样式:[需要('./navbar left.scss')],
模板:require('./navbar left.html'),
})
导出默认类NavbarLeftComponent{
public isAuth:boolean=false;
构造函数(专用会话服务:会话服务){
this.isAuth=sessionService.sessionsauth();
}
}
不知道我到底做错了什么?这是一个子组件。在父组件aka App组件中,ngIf
工作正常。
角度RC5如果使用RC5,则导入以下内容:
import { CommonModule } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser';
并确保从提供组件的模块导入CommonModule
@NgModule({
imports: [CommonModule],
declarations: [MyComponent]
...
})
class MyComponentModule {}
您应该像这样使用*ngIf,而不是[ngIf]:
<div *ngIf="isAuth" id="sidebar">
对于仍然有问题的人,我也遇到了一个问题,我输入了ngif
,而不是ngif
(注意大写字母“I”)。从“@angular/common”导入{CommonModule}
Steve的代码片段应该在答案中。只有我将export
添加到类中时,这个答案才对我有效。不要忘记“声明”,如果在尝试了本页中的所有建议后仍然出现错误,请尝试再次运行“ng serve”。nfIf
在我的情况下,有时…:facepalm:就我而言,我也遇到了同样的问题,我输入了ngif
而不是ngif
@自从我发表这篇评论以来,我们中有多少人都有这个问题,这让我感到惊讶。这是我有史以来得分最高的评论,完全是即兴的。你救了我一天剩下的时间,我在这上面烧了2个小时,一条错误消息是非常不清晰的Anks@Peter short,而且对我也有帮助!!确保您没有使用选择器名称,例如:selector:'duplicatedNameHere,
导入“CommonModule”,并且不要忘记两次执行“ng serve”以克服坏运气。。。