Angular:在app.module.ts中声明的组件在其他组件中找不到



我有一个自定义模态,我想在其他几个组件中重用。但作为一个组成部分,它没有被发现。

获取:

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。我还尝试过为自己制作一个模块,并在";进口:[]";相反

不管怎样,它都不可用。

除了模板中的选择器之外,我还没有在子组件(组件或子模块(中包含对它的引用。

我可以在一个子组件上使用它,当添加到该组件自己的模块时,这样我就知道它在工作。但无法重复使用(作为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,
...

如果组件是在另一个模块中声明的,那么您也必须导出它。

最新更新