Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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
如何调用另一个服务提供商-angularjs2_Angular_Typescript_Angular Services - Fatal编程技术网

如何调用另一个服务提供商-angularjs2

如何调用另一个服务提供商-angularjs2,angular,typescript,angular-services,Angular,Typescript,Angular Services,我有一些产品和购物车清单。下面是使用id循环购物车列表以获取特定产品的函数 getCartList(){ this.cart = CART; this.cart.forEach((cart: Cart) => { let id = parseInt(cart.productid.trim()); //**this.product = this._productService.getProduct(id);

我有一些产品和购物车清单。下面是使用id循环购物车列表以获取特定产品的函数

getCartList(){
        this.cart = CART;
        this.cart.forEach((cart: Cart) => {
            let id = parseInt(cart.productid.trim());
              //**this.product = this._productService.getProduct(id); => Here I need to call another service.**
            });
        });
        console.log(this.cart);
    }

只需在引导应用程序时定义此服务,并将其注入到您想要使用的服务中:

bootstrap(AppComponent, [ CardService , ProductService ]);
在职期间:

@Injectable()
export class CardService {
  constructor(private _productService: ProductService) {
  }
}
别忘了指定@Injectable装饰器

这个问题可以提供更多关于依赖注入、分层注入和注入服务工作原理的详细信息: