首页 > 解决方案 > 在 Angular 7 中链接多个服务调用是个好主意吗

问题描述

我正在创建一个基本的 MEAN 应用程序,在处理它时,我必须一个接一个地调用多个服务。例如,在下订单时:

PlaceOrder(){
   productService.CheckAvailability().subscribe(() => {
       if (available){
          customerService.GetCustomer().subscribe(() =>{
             if(newCustomer){
                   customerService.CreateCustomer().subscribe(() => {
                         orderService.CreateOrder().subscribe(() => {
                                console.log("Order placed");
                          });
                    });
              }
              else //old customer
               {
                     orderService.CreateOrder().subscribe(() => {
                              console.log("order placed");
                      });
                }
          });
       } //endif
   });
}

现在,我想知道以这种方式链接这些服务调用是否是一个好主意和应用程序设计,或者这种设计是否会影响应用程序的速度和效率。Nodejs 服务器也是如此。在那里,我有连续的数据库更新。

标签: node.jsangularweb-servicesexpressdesign-patterns

解决方案


推荐阅读