Creating a Comment Service

Because you know you will need a comment service to handle getting and adding comments, you need to add that first. Listing 27.15 implements a comment service that uses the service method. You need to create a function definition called CommentObj. The constructor function accepts the $http service as the only parameter.

You define a getComment() function that accepts commentId and then does a GET request to the /comment/get route to get the full comment data. Notice that this function also accepts a callback function. The callback function returns an error if $http reports one or the comment data from the server.

The addComment() function accepts rootCommentId for the comment thread, parentId for the parent comment, ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.