最佳答案
Q)如何将以下可观察到的转换为一个承诺,以便我可以用 .then(...)
调用它?
我想把我的方法转换成一个承诺:
this._APIService.getAssetTypes().subscribe(
assettypes => {
this._LocalStorageService.setAssetTypes(assettypes);
},
err => {
this._LogService.error(JSON.stringify(err))
},
() => {}
);
它调用的服务方法:
getAssetTypes() {
var method = "assettype";
var url = this.apiBaseUrl + method;
return this._http.get(url, {})
.map(res => <AssetType[]>res.json())
.map((assettypes) => {
assettypes.forEach((assettypes) => {
// do anything here you might need....
});
return assettypes;
});
}
谢谢!