我觉得我错过了一些非常简单的东西。
我制作了一个空白的离子项目,我需要从URL中提取数据来吐出JSONP。
这就是我的home.ts的样子:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { HttpClientModule} from '@angular/common/http';
import { HttpClient} from '@angular/common/http';
import { RedditData } from '../../providers/reddit-data/reddit-data'
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map'
import 'rxjs/Rx';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/catch';
import { UsingObservable } from 'rxjs/observable/UsingObservable';
import { Jsonp } from '@angular/http';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
result:any = [];
data:Observable<any>;
constructor(public navCtrl: NavController, private http: HttpClient,private json:Jsonp) {
}
ionViewDidLoad(){
var url='/common/v1/airport.json?code=BGW&';
this.data=this.json.request(url,'callback=JSONP_CALLBACK');
this.data.subscribe(data =>{
this.result=data;
console.log(data)
});
}
}
当我在本地服务器上运行时,我会在控制台Google Chrome中收到消息:
GET /common/v1/airport.json?code=BGW& 418()
答案 0 :(得分:0)
试试这个..
this.http.get(`http://url`).subscribe(
data => {
this.result=data;
console.log(data)
});