मैं सेवा जो ठीक काम कर रहा था, जब तक आज मैं यह त्रुटि आई निम्नलिखित है नहीं हैAngular2 RXJS प्रत्यक्ष लेखन त्रुटि के साथ Http:।। This.http.get (...) मानचित्र (...) पकड़ एक समारोह
TypeError: this.http.get(...).map(...).catch is not a function.
जब मैं इस कोड को डीबग कर रहा हूं तो यह कैच विधि की बात आती है।
import { Test } from "./home.component";
import { Injectable } from "@angular/core";
import { Inject } from "@angular/core";
import { Http , Response } from "@angular/http";
import { Observable } from "rxjs/Observable";
@Injectable()
export class HomeService {
public constructor(@Inject(Http) private http: Http) {}
public getData(): Observable<Test []> {
return this.http.get("./src/app/home/home-data.json")
.map(this.extractData).catch(this.handleError);
}
public extractData(res: Response) {
let body = res.json();
return body.data || { };
}
public handleError (error: any) {
// In a real world app, we might use a remote logging infrastructure
// We"d also dig deeper into the error to get a better message
let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : "Server error";
console.error(errMsg); // log to console instead
return Observable.throw(errMsg);
}
}
यह काम किया! धन्यवाद। यह पागल है कि मेरे पास मेरे विक्रेताओं फ़ाइल में यह 'आयात' आरएक्सजे/आरएक्स' है जहां मैं अपनी अन्य निर्भरताओं को कोणीय 2 के लिए भी आयात करता हूं, लेकिन मेरा मानना है कि मुझे इस पुस्तकालय को प्रत्येक फ़ाइल में आयात करने की आवश्यकता है जहां मैं इसे या मुख्य में उपयोग करना चाहता हूं। ts। –
@ थिएरी, स्पष्ट रूप से पूरे आरएक्सजे/आरएक्स आयात करना अच्छा अभ्यास नहीं है। क्या आपको लगता है कि आपको केवल उन ऑपरेटरों को आयात करने में सुधार नहीं है जिन्हें आपको चाहिए? –