AngularJS $scope updates not reflected in the view

前端 未结 2 1327
刺人心
刺人心 2021-01-14 07:20

Firstly I am sorry if I will be confusing, but I\'m solving this issue the whole evening, and I\'ve read dozens of SO questions and AngularJS articles, so I\'m not even sure

相关标签:
2条回答
  • 2021-01-14 07:33

    Can you try the following?

    Change the way you are using $http.post (at both places). Try to use it like:

    $http.post($scope.url, {'filterType': 'abc', 'letter': $routeParams.letter}).success(function(data) {
       $scope.listItems = data;
    });
    

    This means your ng-repeat changes slightly:

    ng-repeat="item in listItems"
    
    0 讨论(0)
  • 2021-01-14 07:48

    Wrapping the initial "state" / defaults for the controller into a function, and calling it upon $viewContentLoaded event helped. Here's my fix:

    $scope.$on('$viewContentLoaded', $scope.init);
    
    $scope.init = function() {
        $scope.mainfilter = $routeParams.letter;
        $scope.listItems = $http.post($scope.url, {'filterType': 'abc', 'letter': $routeParams.letter});
    }
    

    I still have no idea why if the default data was set only by assigning values right in the controller code was causing the view to be "stuck" to this data, so I'm willing to re-accept a better answer, explaining this voodoo.

    0 讨论(0)
提交回复
热议问题