Angular 共享模块导入不导入提到的模块

标签 angular

我已将共享模块添加到我的应用程序中。看起来很简单。

const imports = [
    CommonModule,
    RouterModule,
    BrowserModule,
    FormsModule, ReactiveFormsModule
];


@NgModule({imports})

export class SharedModule {}

当我将共享模块导入另一个模块时,它看不到我导入的人员。我收到这样的错误“无法绑定(bind)到‘formGroup’,因为它不是‘form’的已知属性。(”,这意味着 FormsModule 未正确导入。 如果我将基本模块直接导入到我的应用程序模块中,它就可以正常工作。

非常感谢您的帮助和建议。

最佳答案

您很可能还需要导出这些模块。

通常:

@NgModule({
    imports: [
        SomeModule
    ],
    declarations: [
        ...
    ],
    exports: [
        SomeModule,
    ]
});

另请参阅此 angular多可...

By re-exporting CommonModule and FormsModule, any other module that imports this SharedModule, gets access to directives like NgIf and NgFor from CommonModule and can bind to component properties with [(ngModel)], a directive in the FormsModule.

关于Angular 共享模块导入不导入提到的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54417156/

相关文章:

Angular组件宿主元素宽高均为0

angular - Angular 4.3 中的 HttpInterceptor : Re-send request in interceptor after jwt refresh

forms - 如何在 Angular2 中用数组迭代表单组

angular - 如何在 Angular 应用中实现 CKEditor?

css - 向 Angular Material 工具提示箭头添加阴影

css - 如何在简单条件和三元条件下使用 [ngClass]?

angular - 在 Angular 2 中,如何在按回车键时提交输入类型 ="text"值?

angularjs - 将数据从重复组件传递到嵌入的重复元素

angular - 使用 Angular 8 中的参数函数动态更改 ag-grid 的 Cell Renderer

angular - typescript 中的运行时类型安全