How can I use ng-click to dynamically reload ng-repeat data?

随声附和 提交于 2019-12-03 06:32:20

Add a broadcast in your callback and subscribe to it in your controller.

This should really be in a service btw

itemsService.loadItems = function (setID) {
    $http({
        url: 'get-items/'+setID,
        method: "POST"
    })
    .success(function (data, status, headers, config) {
        $scope.items = data;
        $rootScope.$broadcast('updateItems', data);
    })
    .error(function (data, status, headers, config) {
        $scope.status = status;
    });
}; 

In your controller:

$scope.$on("updateItems",function(d){
  $scope.items = d;
});

So whenever you ng-click="update(id)"

$scope.update = function(id){
    itemsService.loadItems(id);
}

Your items will automatically update because it is subscribed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!