Created
August 22, 2017 21:51
-
-
Save chetkhatri/086dffe1fb29a620dbc303dc2a235405 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Injectable } from '@angular/core'; | |
| import { Http, Response } from '@angular/http'; | |
| import { Observable } from 'rxjs/Rx'; | |
| import { User } from "app/models/user"; | |
| @Injectable() | |
| export class UserService { | |
| constructor(private http: Http) { | |
| } | |
| getUsers(): Observable<User[]> { | |
| return this.http.get("https://jsonplaceholder.typicode.com/users") | |
| .map((res: Response) => res.json()) | |
| .catch((error: any) => Observable.throw(error.json().error || 'Server error')); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment