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

问题描述

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

元素是<div [ngIf]="isAuth" id="sidebar">

该组件是:

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();
  }

}

不确定我到底在做什么错?这是一个子组件.在父组件(也称为App组件)中,ngif起作用.角RC5

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

推荐答案

如果您使用的是RC5,请导入以下内容:

If you are using RC5 then import this:

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

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

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

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

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

09-18 02:00