Ich erhalte den folgenden Fehler. Uncaught TypeError: this.jsonp.request ist keine Funktion in Angular2. Kann mir bitte jemand helfen, das zu beheben.Uncaught TypeError: this.jsonp.request ist keine Funktion in Angular2
Mein Code wird dies mag:
RequestService.ts
import {Component} from '@angular/core'; import {JSONP_PROVIDERS, Jsonp,RequestMethod, RequestOptions, URLSearchParams,JSONP_BINDINGS, BaseRequestOptions} from '@angular/http'; import {Injectable} from '@angular/core'; import 'rxjs/add/operator/map'; @Injectable() @Component({ providers: [JSONP_PROVIDERS] }) export class RequestService { constructor(public jsonp?:Jsonp) { this.jsonp = Jsonp; } getValues = (url) => { let _urlParams = new URLSearchParams(); _urlParams.set('contentType', 'application/jsonp; charset=utf-8'); _urlParams.set('dataType', 'jsonp'); _urlParams.set('timeout', '5000'); this.jsonp.request(url + "&callback=JSONP_CALLBACK", { // getting error here contentType: "application/jsonp; charset=utf-8", dataType: 'jsonp', timeout: 5000 }) .map(res => { return res.json(); }) .subscribe(res => { // here some stuffs with response }), err => { console.log('error') }; } }
abc.ts
import {RequestService} from './../request_service'; export class ABC { private request:any = new RequestService(); bindValues() { this.request.getValues('http://google.co.in'); // note: url given here is sample } }
Vielen Dank im Voraus
Welche Version von Angular2 verwenden Sie? –
Winkelversion 2.0.0-rc.1 @Thierry Templier – Jeni