I have 2 components, first one is modules/pages/home/home.component and the second one is modules/pages/home/components/banner I want to use banner component in home component. when i try to use i get this error
From your folder structure it looks like both components should be part of the same module.
So go to home.module.ts
or whatever @NgModule
you have, and make sure app-banner
is part of the declarations
array.
Alternatively, if app-banner
is part of separate module, be sure to add that other module inside home.module
's import
array.
There should be an app.module.ts
file in your project, inside it you'll find @NgModule
, and then there should be declarations
property (it's an array). Try to insert your BannerComponent
in there and call your banner component using it's selector in home.component.html
.
In the same module
@NgModule({
imports: [...],
declarations: [AComponent,BComponent,...],
})
export class AllInOneModule {}
In different Module
//Module "A"
@NgModule({
imports: [...],
declarations: [AComponent,...],
exports: [AComponent],
})
export class AModule {}
//Module "B"
@NgModule({
imports: [AModule...],
declarations: [BComponent,...],
})
export class BModule {}
导入并在 app.moudle.ts 中声明组件后,它可以工作
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.