Angular 9 - 不是已知元素
Angular 9 - is not a known element
它一直工作到 angular 7 现在更新后它抛出未知元素的错误。它发生在共享模块上。
可重现代码:- https://stackblitz.com/edit/angular-ivy-pb3eea
所以我有一个父组件'Parent',
在 'Parent' 的路由器内使用的子组件 - 'Child'
在父子内部使用的共享组件 - 'Shared'
所以我已经导入了父子模块。 (因为使用惰性模块),在父级它有效但在子级无效。
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TestChildRoutingModule} from './test-child.routing.module';
import { SharedModule } from '../shared/shared.module';
@NgModule({
declarations: [
],
imports: [
CommonModule,
SharedModule,
TestChildRoutingModule
],
exports: [
]
})
export class TestChildModule { }
您在 TestChildModule 中缺少 TestChildComponent 的声明
@NgModule({
declarations: [
TestChildComponent
],
imports: [
CommonModule,
SharedModule,
TestChildRoutingModule
],
exports: [
TestChildComponent
]
})
export class TestChildModule { }
这里是固定的STACKBLITZ
它一直工作到 angular 7 现在更新后它抛出未知元素的错误。它发生在共享模块上。
可重现代码:- https://stackblitz.com/edit/angular-ivy-pb3eea
所以我有一个父组件'Parent', 在 'Parent' 的路由器内使用的子组件 - 'Child' 在父子内部使用的共享组件 - 'Shared'
所以我已经导入了父子模块。 (因为使用惰性模块),在父级它有效但在子级无效。
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TestChildRoutingModule} from './test-child.routing.module';
import { SharedModule } from '../shared/shared.module';
@NgModule({
declarations: [
],
imports: [
CommonModule,
SharedModule,
TestChildRoutingModule
],
exports: [
]
})
export class TestChildModule { }
您在 TestChildModule 中缺少 TestChildComponent 的声明
@NgModule({
declarations: [
TestChildComponent
],
imports: [
CommonModule,
SharedModule,
TestChildRoutingModule
],
exports: [
TestChildComponent
]
})
export class TestChildModule { }
这里是固定的STACKBLITZ