gpt4 book ai didi

javascript - AngularJs - 带 Angular 的书签按钮

转载 作者:行者123 更新时间:2023-12-03 09:05:44 25 4
gpt4 key购买 nike

我想用 angularjs 创建一个书签按钮,我有标记表来存储它,还有一个包含所有帖子的 Json 文件。

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 工厂

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!
});
}
}]);

但这不行,我也尝试了其他方法,但这是最好的!你有什么想法?

最佳答案

我认为它在 $scope.hasMark = !disable;正如您已经建议的那样。我认为您应该更改以下内容:

在您的成功回调函数中:

$scope.hasMark = !$scope.hasMark;

还要确保 $posts.mark.disable存在于 $scope 中。

我制作了一个简化的 Plnkr 来展示我的意思:Plnkr

关于javascript - AngularJs - 带 Angular 的书签按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32188878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com