goodson
goodson

Reputation: 757

$scope lost after asynch call

I had this working in another project, but when I move the code into a fresh project, the most simple case fails.

My controller looks like this:

angular.module('myApp.controllers').
  controller('SchoolController', ['$scope',
  function($scope) {
      $scope.school = "whats wrong";
      var query = new Parse.Query("School");
      query.first().then(function(result){
          $scope.school = "with this";
          alert(result.get("name"));
      });
}]);

And the html looks like this:

<p>school is {{school}}</p>

When rendered, I see "school is what's wrong" on the page as I expect, and I see the alert, including data from the server. But why don't I see the bound variable on the page change to "with this" ??

Thanks

Upvotes: 0

Views: 36

Answers (1)

lante
lante

Reputation: 7336

Apply your changes to angular:

angular.module('myApp.controllers').
  controller('SchoolController', ['$scope',
  function($scope) {
      $scope.school = "whats wrong";
      var query = new Parse.Query("School");
      query.first().then(function(result){
          $scope.school = "with this";
          $scope.$apply();
      });
}]);

See $apply on this link

Upvotes: 1

Related Questions