0

Let's say that when the page is first rendered, the controller has no data to return:

var data={};

function dataController($scope) {
    $scope.resultsToDisplay = data;
}

but as the user works with the page in a variety of ways, information is being assembled "behind the scenes" and is getting appended to data.

How does Angular know when to refresh the UI? Is Angular invoking dataController() periodically? Is there anything special that has to be done to data variable to tell Angular to "observe" it?

Tim
  • 8,669
  • 31
  • 105
  • 183

2 Answers2

1

I think you are looking for the $watch approach.

 function dataController($scope) {    
    $scope.data={};
    $scope.$watch('data', function() {
       $scope.resultsToDisplay = $scope.data;
    });
 }

Here is a much detailed explanation about $watch How do I use $scope.$watch and $scope.$apply in AngularJS?

Community
  • 1
  • 1
0

Since "data" is not a scope variable. I would make a call to scope.$apply() everytime variable "data" is modified.

It will trigger a digest cycle which will update the UI.