Created
October 7, 2017 17:29
-
-
Save tkssharma/3512eddd41f298400a935b667db8fb63 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
// Add a new comment | |
addComment (body: Object): Observable<Comment[]> { | |
let bodyString = JSON.stringify(body); // Stringify payload | |
let headers = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON | |
let options = new RequestOptions({ headers: headers }); // Create a request option | |
return this.http.post(this.commentsUrl, body, options) // ...using post request | |
.map((res:Response) => res.json()) // ...and calling .json() on the response to return data | |
.catch((error:any) => Observable.throw(error.json().error || 'Server error')); //...errors if any | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment