在继续问题之前,我已经检查了其他具有相同标题的问题,并遵循了建议。没有任何帮助,所以我决定打开一个新问题。
我有一个模块和多个组件的角度项目。仪表板组件使用了显然无法识别的欢迎组件。
该模块具有以下代码:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { FrameComponent } from './frame/frame.component';
import { WelcomeComponent } from './welcome/welcome.component';
import { CardComponent } from './card/card.component';
import { AlertComponent } from './alert/alert.component';
@NgModule({
declarations: [
FrameComponent,
HomeComponent,
CardComponent,
WelcomeComponent,
AlertComponent
],
imports: [
BrowserModule,
RouterModule.forRoot([
{
path: '',
component: HomeComponent
},
{
path: 'dashboard',
component: DashboardComponent
}
])
],
exports: [CardComponent, WelcomeComponent, AlertComponent],
providers: [],
bootstrap: [FrameComponent]
})
export class AppModule { }
如您所见,我已经导入了WelcomeComponent,对其进行了声明并导出了它。WelcomeComponent包含以下代码:
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-welcome',
templateUrl: './welcome.component.html',
styleUrls: ['./welcome.component.css']
})
export class WelcomeComponent implements OnInit {
@Input()
message: string;
welcomeMessage: string;
constructor() { }
ngOnInit(): void {
}
}
在这里您可以看到app-welcome作为选择器。它似乎已正确连接。但是当我在示例中给出的dashboard.component.html中使用它时
<app-welcome [message]="message" [welcomeMessage]="welcomeMessage"></app-welcome>
我收到以下错误:
错误:src / app / dashboard / dashboard.component.html:18:5-错误NG8001:'app-welcome'不是已知元素:1.如果'app-welcome'是Angular组件,请验证是否为此模块的一部分。2.如果“ app-welcome”是Web组件,则将“ CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“ @ NgModule.schemas”以禁止显示此消息。
其他错误与Welcome和welcomeMessage不相关,因为无法识别组件。
我尝试重新启动服务器,将其作为--prod运行。我尝试了所有发现的东西。有谁知道这可能是什么原因?
仪表板组件未在您的AppModule中声明,这就是问题所在。同样,在这种情况下,您无需导出组件,只需声明它们即可。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句