我如何得到错误“错误:未捕获承诺:错误:模板解析错误:‘app-customer-list’不是已知元素”

问题描述

我正在尝试加载一个组件,但出现此错误

eRROR
Error: Uncaught (in promise): Error: Template parse errors:
'app-customer-list' is not a kNown element:
1. If 'app-customer-list' is an Angular component,then verify that it is part of this module.
2. If 'app-customer-list' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
</p>

所有代码在这里

https://stackblitz.com/edit/angular-zkciqv?file=src/app/orders/order-list/order-list.component.html

检查组件: 订单 -> 订单列表 -> Order.component.html

为什么没有加载?为什么是错误?如何解决这个问题?

解决方法

首先在您的客户模块中,您需要使用 export 属性将 exports 个组件公开给其他模块:

customers.module.ts

@NgModule({
  imports: [
    CommonModule,CustomersRoutingModule
  ],declarations: [CustomerListComponent],exports: [CustomerListComponent]
})
export class CustomersModule { }

接下来,您需要将 import CustomersModule 放入将使用该模块导出的组件的模块中:

orders.module.ts

@NgModule({
  imports: [
    CommonModule,OrdersRoutingModule,CustomersModule
  ],declarations: [OrderListComponent]
})
export class OrdersModule { }

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...