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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access