refactor(http): use Observables in Http backends
BREAKING CHANGE: Http now returns Rx Observables directly, so calling .toRx() is no longer necessary. Additionally, Http calls are now cold, so backend requests will not fire unless .subscribe() is called. closes #4043 and closes #2974 Closes #4376
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import {Component, View, NgFor} from 'angular2/angular2';
|
||||
import {Http, Response} from 'angular2/http';
|
||||
import {ObservableWrapper} from 'angular2/src/core/facade/async';
|
||||
import {Http} from 'angular2/http';
|
||||
|
||||
@Component({selector: 'http-app'})
|
||||
@View({
|
||||
@ -16,8 +15,5 @@ import {ObservableWrapper} from 'angular2/src/core/facade/async';
|
||||
})
|
||||
export class HttpCmp {
|
||||
people: Object;
|
||||
constructor(http: Http) {
|
||||
ObservableWrapper.subscribe<Response>(http.get('./people.json'),
|
||||
res => this.people = res.json());
|
||||
}
|
||||
constructor(http: Http) { http.get('./people.json').subscribe(res => this.people = res.json()); }
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import {ObservableWrapper} from 'angular2/src/core/facade/async';
|
||||
export class JsonpCmp {
|
||||
people: Object;
|
||||
constructor(jsonp: Jsonp) {
|
||||
ObservableWrapper.subscribe<Response>(jsonp.get('./people.json?callback=JSONP_CALLBACK'),
|
||||
res => this.people = res.json());
|
||||
jsonp.get('./people.json?callback=JSONP_CALLBACK').subscribe(res => this.people = res.json());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user