How make ngIf directive globally visible in all project?

一世执手 提交于 2020-01-30 05:29:10

问题


I have a code <div class="flex-container" *ngIf="mail"> Some data </div>

And i have a error Can't bind to 'ngIf' since it isn't a known property of 'div'.

How i can fix it?


回答1:


Import BrowserModule in the root module and CommonModule in other modules where you want to use common directives.

@NgModule({
  imports: [BrowserModule],
  ...
})
class AppModule {}

and

@NgModule({
  imports: [CommonModule],
  // Now MyComponent has access to ngIf
  declarations: [MyComponent]
  ...
})
class OtherModule {}

BrowserModule exports CommonModule, this way it's not necessary to import CommonModule directly in the root module.



来源:https://stackoverflow.com/questions/39746142/how-make-ngif-directive-globally-visible-in-all-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!