首页 > 解决方案 > 如何在多个组件中使用服务调用?

问题描述

我必须在多个组件中使用这些服务调用,但我在重用代码时遇到了问题。如何使这段代码可重用?

//For Permanent Countries
this.service.getCountries().subscribe((response: any) => {
  this.permanentCountries = response;
});

//For Temporary Countries
this.service.getCountries().subscribe((response: any) => {
  this.temporaryCountries = response;
});

//For Genders
this.service.getGenders().subscribe((response: any) => {
  this.genders = response;
});

标签: angularangular7angular-services

解决方案


推荐阅读