| import { Injectable } from 'angular2/core'; | |
| import { Http, Response } from "angular2/http"; | |
| import { Observable } from "rxjs/Observable"; | |
| import * as _ from "js/lodash.js"; | |
| | |
| import { Foo } from "./foo"; | |
| | |
| @Injectable() | |
| export class FooService { | |
| fooList: Observable<Foo[]>; | |
| | |
| constructor(private _http: Http) { | |
| | |
| this.fooList = this._http.get('http://localhost:9090/api/').map( | |
| response => { | |
| var json = response.json(); | |
| if(response.ok === true) { | |
| let newFooList: Foo[] = []; | |
| _.forEach(json, f => { | |
| newFooList.push(new Foo(f)); | |
| }); | |
| return newFooList; | |
| } | |
| throw Error("Bad status: " + response); | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment