Angular 4个模块相互调用
假设我有两个模块:客户/订单如下:Angular 4个模块相互调用,angular,circular-dependency,Angular,Circular Dependency,假设我有两个模块:客户/订单如下: /customers /customers-list.component.html /customers-list.component.ts /customers-details.component.html /customers-details.component.ts /customers-create.component.html /customers-create.component.ts /cu
/customers
/customers-list.component.html
/customers-list.component.ts
/customers-details.component.html
/customers-details.component.ts
/customers-create.component.html
/customers-create.component.ts
/customers.service.ts
/customers.module.ts
/orders
/orders-list.component.html
/orders-list.component.ts
/orders-create.component.html
/orders-create.component.ts
/orders.service.ts
/orders.module.ts
两者都在使用各自的服务(通过在模块中使用提供商
)
orders.module
导入customers.module
,因为在我的orders create.component.ts
中,我有一个表单,可以在其中为客户添加新订单。如果客户端不存在,我可以按一个按钮并显示customers create.component
但是现在,我需要通过调用订单列表.component
,在我的客户详细信息.component中添加给定客户的订单列表
但是由于循环依赖关系,我无法在我的客户模块
中导入订单
模块
那么:在这种情况下,最好的方法是什么?是否需要为我的订单列表组件创建共享模块
两者都在使用各自的服务(通过使用模块中的提供者)
我认为这是一种错误的方法,您应该隔离(从逻辑)服务来处理请求(如API服务),该服务将被定义一次,并且可以在任何地方重用 您可以制作第三个模块,该模块构成您要查找的视图。这允许您继续拥有特定于域的组件(order
和customer
),但可以创建不同但仍然可重用的页面
例如:
您的客户视图。组件将使用客户详细信息.component
和订单列表.component
创建您描述的完整视图
您的orders create.component.ts
也应该存在于这个新模块中,因为它使用客户组件
*免责声明:根据您的意愿命名模块,这只是一个示例。创建一个新模块,该模块同时包含这两个模块,并且新模块具有组合布局组件。您所说的@ps2goat是什么意思?你有没有举个例子?
/pages
/customer-view.component
/orders-create.component.ts