如何使 ngIf 指令在所有项目中全局可见?

How make ngIf directive globally visible in all project?

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

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

我该如何解决?

在根模块中导入 BrowserModule 并在其他要使用通用指令的模块中导入 CommonModule

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

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

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