【发布时间】:2019-05-14 05:38:47
【问题描述】:
我正在寻找转换这个使用 angular/http 的请求,以便我可以在物理设备上获得结果:
import { Http } from '@angular/http'; //old way
import { HTTP } from '@ionic-native/http'; //new way
angular/http 请求
function getWeather() {
return this.http.get(this.url + '/' + latitude + ',' + longitude)
.map(res => res.json());
}
调用的方法,使用'subscribe'
this.weatherProvider.getWeather(latitude, longitude).subscribe(results => {
console.log(results);
});
我想将其转换为原生/http,可作为 Ionic 中的插件使用
它可能看起来像这样:
function getWeather() {
return this.httpNative.get(this.url + '/' + latitude + ',' + longitude, {}, {})
.then(data => {
console.log(data.data);
})
.catch(error => {
console.log(error.error);
});
}
但是,我在此方法中接收数据时遇到了一些问题,因为我无法再订阅结果并且它没有被映射...我收到空结果
this.weatherProvider.getWeather(latitude, longitude).subscribe(results => {
console.log(results);
});
【问题讨论】:
标签: angular http ionic-framework