我想创建一个带有angularjs的书签按钮,我有标记表来存储它,也是一个包含所有帖子的Json文件。AngularJs - 带有角度的书签按钮
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>
角厂
app.factory('posts', ['$http', function($http) {
return $http.get('http://localhost/index.php/q')
.success(function(data) {
return data;
})
.error(function(data) {
return data;
});
}]);
角控制器:
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!
});
}
}]);
但它不是WO rk,我尝试了另一种方法,但它是最好的! 你的想法是什么?
可以复制?检查http://stackoverflow.com/questions/29586075/add-a-bookmark-page-button-with-angular –
@AmosBordowitz - 我检查之前,但我的代码是不同的。不是吗? – Andrew