我有一个自定义模式,我想在其他几个组件中重用。但作为一个组件,它没有被发现。
获取:
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.
我在app.module的base/root中以两种方式注册了app.module中的组件:
1.与“声明:[]”和
中的组件一样
2. 我也尝试过为自己制作一个模块并在“imports:[]”中注册。
无论如何它都不可用。
除了模板中的选择器之外,我没有在子组件(组件或子模块)中包含对它的引用。
我可以在添加到该组件自己的模块时在单个子组件上使用它,所以我知道它正在工作。但不能重用(这很烦人,因为它是 Angular 的基本租户,哈哈)
有什么建议吗?
ps。我的模块的内容从第 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,
...
答案 0 :(得分:0)
如果组件是在另一个模块中声明的,您还必须将其导出。