-1
任何人都可以帮助我如何使用http请求上的Observable来处理成功,失败和拒绝情况?在组件如何使用angular2 Observable
import { Injectable } from '@angular/core';
import { Http, Response, Headers } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';
@Injectable()
export class MyService {
constructor(private _http: Http) {
}
private handleError(error: Response) {
console.error(error);
return Observable.throw(error.json().error || "Server error");
}
getMethod(): Observable<any> {
return this._http.get("yourGetUrl")
.map((response: any) => <any>response.json())
.catch(this.handleError);
}
}
然后:
https://angular.io/docs/ts/latest/guide/server-communication.html – echonax
是什么标题有问题怎么办? – 2017-05-09 12:05:48