[英]Angular Http get with observable
I know that has a lot of questions about this, but i tried a lot of tips and the problem persists. 我知道这有很多问题,但是我尝试了很多技巧,问题仍然存在。
i implement a get that return an observable: 我实现了一个get,返回了一个可观察到的:
public getEstatisticasPara(motorista:Motorista): Observable<EstatisticaAvaliacao> {
let params = new URLSearchParams();
params.set(Config.ESTATISTICA_AVALIACAO_REQUEST_PARAM, motorista.getId().toString());
let options = new RequestOptions({ headers: this.headers, params: params });
return this.http.get(this.path, options)
.map((res) => res.json)
.catch(this.handleError);
}
When i try to subscribe always get a undefined: 当我尝试订阅时,总是得到未定义的内容:
atualizaMediaAvalicaoes(){
let motorista:Motorista = FlyweightFactory.getInstanceOf("motorista");
motorista.setId(1);
this.estatisticaAvaliacaoProvider.getEstatisticasPara(motorista)
.subscribe((res)=>{
console.log(JSON.stringify(res));
let estatisticaAvaliacao:EstatisticaAvaliacao = EstatisticaAvaliacao.fromJson(res);
this.storage.set("mediaAvaliacao", estatisticaAvaliacao.getMedia());
},(err)=>{
console.log(err);
});
}
Network console show correct response... so why the undefined ? 网络控制台显示正确的响应...那么为什么未定义? =/
= /
This 这个
.map((res) => res.json)
should be this: 应该是这样的:
.map((res) => res.json())
Notice the additional parentheses. 注意其他括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.