How make ngIf directive globally visible in all project?

后端 未结 1 1945
悲哀的现实
悲哀的现实 2021-01-19 12:24

I have a code

Some data

And i have a error Can\'t bind to \'ngIf\' since it isn\'

1条回答
  •  隐瞒了意图╮
    2021-01-19 13:10

    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.

    0 讨论(0)
提交回复
热议问题