Chapter 11Adding a Comment System to Single Page Blogger

Every blogging app has an integrated comment system and obviously our Single Page Blogger would be incomplete without one. We're going to build a simple comment system by creating a custom directive. Let's name this directive spb-comments. Here is its initial structure:

angular.module('spBlogger.posts.directives',[]).
↵directive('spbComments',function(Post){
   return {
       restrict:'AEC',
       scope:{
           postInstance:'='
       },
       replace:true,
       link:function(scope,elem,attrs){

       },
       templateUrl:'modules/posts/views/comments.html'
   }
});

The code goes into the file: modules/posts/js/directives.js.

As you can see, the directive creates an isolated scope. The isolated scope has a property called postInstance. The ...

Get AngularJS: Novice to Ninja 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.