首页 > 解决方案 > 未捕获的错误:模块“AppModule”声明的意外值“未定义”

问题描述

收到以下错误,例如未捕获的错误:模块“AppModule”声明的意外值“未定义”。我已正确导入所有模块。但是,它仍然显示相同的错误。谁能给出解决方案?

我的错误截图

我的代码是,

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { ProductListComponent } from './products/product-list.component';


@NgModule({
declarations: [
AppComponent,
ProductListComponent
],
imports: [ 
BrowserModule
], 
bootstrap: [AppComponent]
})
export class AppModule { }

产品列表.component.ts

 import { Component } from '@angular/core';

 @Component({
 selector:`pm-products`,
 templateUrl:'./product-list.component.html',
 styleUrls: ['./product-list.component.css']
 })

export class ProductListComponent {
pageTitle: string='Product List';
}

标签: angular

解决方案


在 index.html 中,将选择器更改为<pm-root>. Angularapp.component在启动时引导您,如 中所示app.module。在你的 app.component 中,你有你的选择器,<pm-root>但在 index.html 中,它是<my-app>. 不存在具有此类选择器的组件,因此您会收到错误消息。


推荐阅读