Implementing the Photo Controller

Next, you need to implement a controller to support the photo portion of the page. Listing 27.16 shows the photoController code. Notice that commentSrv is injected into the controller, along with the $http service.

The controller initializes $scope.photos and $scope.photo, using an $http GET request to the /photos route. The $scope.loadComments() function uses the commentSrv.getComment() function to retrieve the comments for the current photo by passing $scope.photo.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 for a comment reply in the template. Notice that it first generates a newComment object ...

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.