[英]Getting error while displaying a component in lazy loaded module in Angular
I have created a component and its name is s-header.我创建了一个组件,它的名称是 s-header。 This component is registered in HomeModule because its a part of this module, but when i try to display this component in home.component.html it gives me this erorr.这个组件在 HomeModule 中注册,因为它是这个模块的一部分,但是当我尝试在 home.component.html 中显示这个组件时,它给了我这个错误。
If 's-header' is an Angular component, then verify that it is part of this module.如果“s-header”是 Angular 组件,则验证它是否是该模块的一部分。
If 's-header' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.如果“s-header”是 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”以禁止显示此消息。
here is my code这是我的代码
import { HeaderComponent } from '../../general-components/header/header.component';
declarations: [
HeaderComponent,
],
this is a header component这是一个 header 组件
import { Component, OnInit } from '@angular/core';
@Component({
selector: 's-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.css']
})
export class HeaderComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
this is how i am trying to display it这就是我试图展示它的方式
<s-header></s-header>
If this is a version of Angular without Ivy - you'll need to also add this component into the entry component array of the lazy loaded module.如果这是没有 Ivy 的 Angular 版本 - 您还需要将此组件添加到延迟加载模块的入口组件数组中。 Its because the factory for this component doesn't exists (because its coming from a lazy loaded module)这是因为该组件的工厂不存在(因为它来自延迟加载的模块)
Simply:简单地:
import { HeaderComponent } from '../../general-components/header/header.component';
declarations: [
HeaderComponent,
...
],
entryComponents: [
HeaderComponent
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.