0

I have some product and cart list. Here is the function to loop the cart list to get the particular product using 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);
    }

1 Answers1

0

Just define this service when bootstrapping your application and inject it in the service you want to use it:

bootstrap(AppComponent, [ CardService , ProductService ]);

In the service:

@Injectable()
export class CardService {
  constructor(private _productService: ProductService) {
  }
}

Don't forget to specify the @Injectable decorator.

This question could give more details on how dependency injection, hierarchical injectors and injection into services work:

Community
  • 1
  • 1
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360