Implementing the Page AngularJS Controller

Next, you need to implement a controller to support the webpage comments. Listing 27.17 shows the pageController code. Notice that commentSrv is also injected into this controller, along with the $http service.

The controller initializes $scope.page, makes an $http GET request to /pages, and passes the hard-coded "Photos Page" name as a parameter. The $scope.loadComments() function calls the commentSrv.getComment() function to retrieve the comments for the page by $scope.page.commentId. The callback function simply sets the $commentThread value that is used in the view.

The $scope.addReply() method is called when the user clicks Send in the page comments template. Notice that it first generates a newComment ...

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.