【问题标题】:How make ngIf directive globally visible in all project?如何使 ngIf 指令在所有项目中全局可见?
【发布时间】:2017-02-06 08:28:52
【问题描述】:

我有一个代码<div class="flex-container" *ngIf="mail"> Some data </div>

我有一个错误Can't bind to 'ngIf' since it isn't a known property of 'div'.

我该如何解决?

【问题讨论】:

    标签: angular typescript frontend angularjs-ng-if


    【解决方案1】:

    在根模块中导入BrowserModule,在您想使用通用指令的其他模块中导入CommonModule

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

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

    BrowserModule导出CommonModule,这样就不需要在根模块中直接导入CommonModule了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-13
      • 2017-05-21
      • 2018-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多