私はStatbureauのインフレーションAPI-https://www.statbureau.org/en/inflation-apiからAngular 2を使用してデータを取得しようとしています。私は自分のAPIをテストし、コンソールに成功メッセージを出力することを開始しています。私が使用しているJSONアドレスのため、使用しているAPIはJSONPであるようです。http://www.statbureau.org/calculate-inflation-price-jsonp?jsoncallback=?ウェブサイトでは、jqueryを使用してapiへの呼び出しを成功させるJSフィドルを提供しています。私は角2で同じ呼び出しをしようとすると、私は、次のエラーを取得:ここHttp get Angular 2
TypeScript error: C:/Users/Rennie/projects/inflator/app/pages/home/home.ts(22,13): Error TS
2322: Type 'Observable<any>' is not assignable to type 'HomePage'.
Property 'jsonp' is missing in type 'Observable<any>'.
TypeScript error: C:/Users/Rennie/projects/inflator/app/pages/home/home.ts(22,13): Error TS
2409: Return type of constructor signature must be assignable to the instance type of the c
は私のコードは、私は、ハードコーディングされたので、私のコードはjsfiddleでコールとは異なり
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import {Jsonp, URLSearchParams } from '@angular/http';
import {Observable} from 'rxjs/Rx';
import 'rxjs/add/operator/map';
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
constructor(private jsonp: Jsonp) {
this.jsonp=jsonp;
let cpiUrl = "https://www.statbureau.org/calculate-inflation-price-jsonp?jsoncallback"
let params = new URLSearchParams();
params.set('country', 'united-states');
params.set('amount', '102');
params.set('start', '1968/1/1');
params.set('finish', '2016/1/1');
// TODO: Add error handling
return this.jsonp
.get(cpiUrl, { search: params }).map(function(response){ return response.json(); })
}
}
ですapiのパラメータはすぐに結果をすぐに見ることができます。
新しいエラーが発生したため、再送信しました。http://stackoverflow.com/questions/38401935/jsonp-request-error-angular-2 – RSB