AngularJS $scope updates not reflected in the view

前端 未结 2 1332
刺人心
刺人心 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: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.

提交回复
热议问题