有没有办法在 Angular StandAlone 的所有模块中提供通用模块?

问题描述 投票:0回答:1

在每个组件中,我都必须导入此 CommonModule 才能使用 NgIf 等指令。

我想要一种在我的所有模块中注入此模块的方法。

   @Component({
      selector: 'app-register',
      standalone: true,
      imports: [ReactiveFormsModule, CommonModule, TextInputComponent],
      templateUrl: './register.component.html',
      styleUrl: './register.component.scss'
    })
angular module angular-module angular-standalone-components
1个回答
0
投票

您需要在导入中指定模块,这是解决服务和其他依赖项时不可避免的。

您可以使用这种常用方法

创建一个共享模块文件并添加 -“导入和导出”公共模块/某些表单模块(在所有/大多数模块中使用的模块),然后在组件文件中导入该共享模块。它会减少没有。独立组件中的导入行。

© www.soinside.com 2019 - 2024. All rights reserved.