AngularJS - refresh ng-repeat

后端 未结 5 722
Happy的楠姐
Happy的楠姐 2021-02-02 07:05

I\'m using ng-repeat to display a collection of values. My filter options changes according to an ajax call to server. How can I refresh the ng-repeat after the filter parameter

相关标签:
5条回答
  • 2021-02-02 07:18

    You need to tell angular that the values have changes:

    $scope.loadNewFilter = function (){
        $scope.filter = [1,2,3];      
        $scope.$apply();
    }
    
    0 讨论(0)
  • 2021-02-02 07:26

    You have placed <button ng-click="loadNewFilter()"> filter now</button> out of controller scope.

    0 讨论(0)
  • 2021-02-02 07:26

    After receiving your filter called $scope.$apply() as following: It is refresh your scope.

    $scope.$apply(function() {
         // your code
    });
    
    0 讨论(0)
  • 2021-02-02 07:30

    In my case I had a trackBy in my ng-repeat and had to remove it to get it to update.

    0 讨论(0)
  • 2021-02-02 07:36

    I didnt need to use $scope.apply() to see the update. What solved this error for me was to make sure:

    1. The update was being called from inside the controller.
    2. The controller that called the update was the same that contained the ng-repeat.
    0 讨论(0)
提交回复
热议问题