因此,在我的项目中,我有一个共享模块,除其他外,我要在其中导入所有Angular材质模块。我的代码构建并运行正常。问题是在我的html文件中,在vs代码中,每个角形材料组件标签下都有红色的波浪线,错误:
'mat-select' is not a known element:
1. If 'mat-select' is an Angular component, then verify that it is part of this module.
2. If 'mat-select' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.ng(0)
我尝试重新启动IDE。如果将物料模块直接导入到模块中,而不是通过共享模块导入,则该消息不会消失。无论如何,这是我的代码:
shared.module.ts
...
@NgModule({
imports: [
CommonModule,
ReactiveFormsModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
FlexLayoutModule,
MatListModule,
MatSelectModule,
MatSidenavModule,
MatToolbarModule
],
exports:
[
ReactiveFormsModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
FlexLayoutModule,
MatListModule,
MatSelectModule,
MatSidenavModule,
MatToolbarModule
]
})
export class SharedModule { }
product.module.ts
...
@NgModule({
declarations: [
ProductComponent,
ProductFormComponent,
AddProductToStoreFormComponent,
StorePickerComponent,
StorePickerRootComponent,
SizeFormComponent,
CategoryPickerRootComponent,
CategoryPickerComponent
],
imports: [
CommonModule,
ProductRoutingModule,
SharedModule
]
})
export class ProductModule { }
感谢您的光临。
答案 0 :(得分:1)
为什么要在“导出”部分中导出其他模块?导出允许其他模块访问声明您的模块的组件/管道。不是模块。
因此,在product.module.ts中,导入MatFormFieldModule
答案 1 :(得分:1)
我知道了。我还安装了nativescript,并按照提示使用@src路径导入共享模块:
import { SharedModule } from '@src/app/shared/shared.module';
一旦我同意使用相对路径:
import { SharedModule } from '../../shared/shared.module';
一切正常。