angular - 如何在多个组件中使用服务调用?
问题描述
我必须在多个组件中使用这些服务调用,但我在重用代码时遇到了问题。如何使这段代码可重用?
//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;
});
解决方案
推荐阅读
- php - kahlan - 单元测试不起作用 - 获取 - 异常`代码(0),消息“未定义变量`请求`
- go - 在 Go 中加载 Windows DLL?
- java - 如何在 mapbox 导航应用程序 (android) 中添加地点插件?
- ruby-on-rails - Heroku:尽管运行 gem install bundler,但无法通过 Bundler 安装 gem
- mysql - 外键说明
- python - 在 Python 中以翻转方向制作空心三角形
- scala - 在 SBT 中编译 spark 程序时出现错误
- django - 如何使用soap在python中的两个跨度id之间获取值
- php - 在 WooCommerce 中获取特定城市的运输区域
- symfony - Sonata Media Bundle - 如何按 ID 获取图像或画廊