Surasin Tancharoen Surasin Tancharoen - 3 months ago 17
AngularJS Question

Angularjs model does not render when change in DWR call back

I have a problem when try to change 'model' in DWR call back.

function mainCtrl($scope) {
$scope.mymodel = "x"; // this is ok
DWRService.searchForSomething(function(result){
$scope.mymodel = result; // PROBLEM!!! it does not rerender the new value
}
$scope.mymodel = "y"; // this is also ok.
}


Anyone has any ideas?

Answer

I'm not super familiar with DWR, but my guess is that you need an $scope.$apply to enclose your model change. Like so:

function mainCtrl($scope) {
   $scope.mymodel = "x";  // this is ok
   DWRService.searchForSomething(function(result){
       $scope.$apply(function() {
            $scope.mymodel = result; // PROBLEM!!! it does not rerender the new value
       });
   });
   $scope.mymodel = "y";  // this is also ok.
}
Comments