[英]angular child html referencing component declared in app.module.ts
[英]Angular: Component declared in app.module.ts not found in other components
我有一個自定義模式,我想在其他幾個組件中重用。 但作為一個組件,它沒有被發現。
得到:
NG0304: 'app-addtoplanner' is not a known element:
1. If 'app-addtoplanner' is an Angular component, then verify that it is part of this module.
2. If 'app-addtoplanner' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
我在 base/root app.module 中以兩種方式在 app.module 中注冊了組件:
1. 與“聲明:[]”中的組件一樣
2. 我也試過自己制作一個模塊,然后在“imports: [ ]”中注冊。
無論哪種方式,它都不可用。
除了模板中的選擇器之外,我沒有在子組件(組件或子模塊)中包含對它的引用。
當添加到組件自己的模塊時,我可以在單個子組件上使用它,所以我知道它正在工作。 但無法重復使用(這很煩人,因為它是 Angular 的基本租戶,哈哈)
有什么建議嗎?
附言。 我的第 2 點模塊的內容如下:
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { AddToPlannerComponent } from './add-to-planner/add-to-planner.component';
@NgModule({
imports: [
CommonModule,
],
declarations: [
AddToPlannerComponent
],
exports:
[
AddToPlannerComponent,
CommonModule
]
})
export class AddToPlannerModule { }
這是在我的 app.module 中導入的
import {AddToPlannerModule} from './views/planner/add-to-planner.module'
@NgModule({
imports: [
AddToPlannerModule,
...
如果該組件在另一個模塊中聲明,您也必須將其導出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.