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.
HTML:
// Using angular ng-repeat loops over the posts.
<button ng-click="ajax( 'storeBookmark', post.id, post.mark.disable);" ng-init="hasMark = post.mark.disable">
<span ng-show="hasMark" class='coreSpriteBookmarkFull32'></span>
<span ng-hide="hasMark" class='coreSpriteBookmarkOpen32'></span>
</button>
Angular Factory
app.factory('posts', ['$http', function($http) {
return $http.get('http://localhost/index.php/q')
.success(function(data) {
return data;
})
.error(function(data) {
return data;
});
}]);
Angular Controller:
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!
});
}
}]);
But it's not work, I tried another ways too but it is best of them! What's your idea?