我在 SharedModule 中添加了一个组件,我需要在延迟加载模块中使用它,但是从共享模块导出组件并在延迟加载模块中导入 SharedModule 后发生事件,我收到此错误。
任何建议都会有帮助。
'shared-component' is not a known element:
1. If 'shared-component' is an Angular component, then verify that it is part of this module.
2. If 'shared-component' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the
'@NgModule.schemas' of this component to suppress this message.
14 <shared-component [main_title]="main_title" [sub_title]="sub_title" [img_src]="img_src">
</shared-component>
共享组件
export class SharedComponent {
@Input() main_title: string = '';
@Input() sub_title: string = '';
@Input() img_src: string = '';
}
延迟加载组件
<shared-component [main_title]="main_title" [sub_title]="sub_title" [img_src]="img_src"></shared-component>
共享模块
@NgModule({
declarations: [
SharedComponent
],
imports: [
CommonModule,
],
exports:[
SharedComponent
]
})
export class SharedModule { }
延迟加载模块
@NgModule({
declarations: [
LazyloadedComponent,
],
imports: [
CommonModule,
FormsModule,
LazyloadedRoutingModule,
SharedModule
],
})
export class LazyloadedModule { }
您的组件似乎缺少 @Component 注释。
@Component({
selector: 'shared-component',
templateUrl: './shared-component.component.html',
styleUrls: ['./shared-component.component.scss'],
})
export class SharedComponent {
@Input() main_title: string = '';
@Input() sub_title: string = '';
@Input() img_src: string = '';
}