无法绑定到“ngIf",因为它不是“div"的已知属性 [英] Can't bind to 'ngIf' since it isn't a known property of 'div'

查看:46
本文介绍了无法绑定到“ngIf",因为它不是“div"的已知属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<块引用>

无法绑定到 'ngIf',因为它不是 'div' 的已知属性.

元素是

组件是:

import SessionService from '../session/session.service';从@angular/core"导入{组件};@成分({提供者:[],选择器:'导航栏左',样式:[require('./navbar-left.scss')],模板:需要('./navbar-left.html'),})导出默认类 NavbarLeftComponent {公共 isAuth: boolean = false;构造函数(私有会话服务:会话服务){this.isAuth = sessionService.sessionIsAuth();}}

不确定我到底做错了什么?这是一个子组件.在父组件 aka App 组件中 ngIf 工作正常.角 RC5

解决方案

如果您使用的是 RC5,请导入:

import { CommonModule } from '@angular/common';从'@angular/platform-b​​rowser' 导入 { BrowserModule };

并确保从提供组件的模块中导入 CommonModule.

 @NgModule({进口:[CommonModule],声明:[MyComponent]...})类 MyComponentModule {}

Can't bind to 'ngIf' since it isn't a known property of 'div'.

The element is <div [ngIf]="isAuth" id="sidebar">

And the component is:

import SessionService from '../session/session.service';
import { Component } from '@angular/core';

@Component({
  providers: [],
  selector: 'navbar-left',
  styles: [require('./navbar-left.scss')],
  template: require('./navbar-left.html'),
})
export default class NavbarLeftComponent {
  public isAuth: boolean = false;

  constructor(private sessionService: SessionService) {
    this.isAuth = sessionService.sessionIsAuth();
  }
}

Not sure what exactly I'm doing wrong? This is a child component. In the parent component aka App component the ngIf works fine. Angular RC5

解决方案

If you are using RC5 then import this:

import { CommonModule } from '@angular/common';  
import { BrowserModule } from '@angular/platform-browser';

and be sure to import CommonModule from the module that is providing your component.

 @NgModule({
    imports: [CommonModule],
    declarations: [MyComponent]
  ...
})
class MyComponentModule {}

这篇关于无法绑定到“ngIf",因为它不是“div"的已知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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