【发布时间】:2017-03-10 10:43:12
【问题描述】:
我创建的网络服务应该使用 1 个参数发送 get 请求, 我应该从 API 中得到结果,
NetworkServices.ts
import { Injectable } from '@angular/core';
import {Http} from "@angular/http";
@Injectable()
export class NetworkServices{
constructor(public http:Http){
}
getCurrency(obj){
console.log("function fired!")
let url = 'http://api.fixer.io/latest?base='+obj.selectedCurrency;
console.log(obj);
this.http.get(url)
.toPromise()
.then( (res) => {
return res;
}
)
}
}
结果应该是 res,这是 3 周前的工作,我不知道 angular 是如何改变的,呵呵..
错误代码是:
[19:46:04] transpile update started ...
[19:46:06] typescript: D:/ionic/firstApp/src/services/network.ts, line: 25
Property 'toPromise' does not exist on type 'Observable<Response>'.
L24: return this.http.get(url).toPromise();
[19:46:06] transpile update failed L25:
}
[19:46:06] watch ready
希望你们能解决这个问题:)
【问题讨论】:
-
预期的行为是什么?实际行为是什么?
-
你有什么资源吗???检查 API
url是否命中正确的 api.. -
也添加一个 .catch() ,如果有则显示错误。
-
嘿伙计们,我只是更新了我添加错误的问题。 @GünterZöchbauer; @Gnujeremie; @micronyks;
-
你必须导入
toPromise
标签: angular ionic2 get-request