Skip to content

Instantly share code, notes, and snippets.

@chetkhatri
Created August 22, 2017 21:51
Show Gist options
  • Select an option

  • Save chetkhatri/086dffe1fb29a620dbc303dc2a235405 to your computer and use it in GitHub Desktop.

Select an option

Save chetkhatri/086dffe1fb29a620dbc303dc2a235405 to your computer and use it in GitHub Desktop.
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