Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 4个模块相互调用_Angular_Circular Dependency - Fatal编程技术网

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