Created
October 7, 2017 17:26
-
-
Save tkssharma/71d70c57ebea1cd0d9aee30475bf2fb5 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
@Injectable() | |
export class CommentService { | |
// Resolve HTTP using the constructor | |
constructor (private http: Http) {} | |
// private instance variable to hold base url | |
private commentsUrl = 'http://localhost:3000/api/comments'; | |
} | |
getComments() : Observable<Comment[]> { | |
// ...using get request | |
return this.http.get(this.commentsUrl) | |
// ...and calling .json() on the response to return data | |
.map((res:Response) => res.json()) | |
//...errors if any | |
.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