title: AngularJs - Bookmark button with Angular
body: <p>I want to create a bookmark button with angularjs and I have marks table to store that, also a Json file that contain all of the posts.</p>
  
  <p><strong>HTML</strong>:</p>
  
  <pre><code>// Using angular ng-repeat loops over the posts.
  &lt;button ng-click="ajax( 'storeBookmark', post.id, post.mark.disable);" ng-init="hasMark = post.mark.disable"&gt;
    &lt;span ng-show="hasMark" class='coreSpriteBookmarkFull32'&gt;&lt;/span&gt;
    &lt;span ng-hide="hasMark" class='coreSpriteBookmarkOpen32'&gt;&lt;/span&gt;
  &lt;/button&gt;
  </code></pre>
  
  <p><strong>Angular Factory</strong></p>
  
  <pre><code>app.factory('posts', ['$http', function($http) {
    return $http.get('http://localhost/index.php/q')
           .success(function(data) {
             return data;
           })
           .error(function(data) {
             return data;
           });
  }]);
  </code></pre>
  
  <p><strong>Angular Controller</strong>:</p>
  
  <pre><code>app.controller('WallController', ['$scope',"$http", 'posts', function($scope,$http, posts) {
    $scope.hasMark = false;
    posts.success(function(data) {
      $scope.posts = data.factory.data;
      $scope.user = data.user;
    });
    $scope.ajax = function(store,post_id,disable){
      $http.post('http://localhost/index.php/question/'+post_id+'/'+store)
        .success(function (data) {
          $scope.hasMark = !disable; //*** this is the problem!
        });       
    }
  }]);
  </code></pre>
  
  <p>But it's not work, I tried another ways too but it is best of them!
  What's your idea?</p>