Friday, August 16, 2013

AngularJS and AJAX - angular is not updating / refreshing

if u'll try to make an AJAX based angluar app u'll run in a few problems of data not updating right.

thats becuz the $http.get/post runz async and ur controllers and direcitves finish their jobs, and even if u call them again sometimes its not enough.

so 1st thing is to use some broadcasting, in the service family there is $rootScope.$broadcast('eventName'); the controllers use  $rootScope.$emit('eventName'); and u can even send args with them.

then in the controllers / directives u should do this:
scope.$root.$on('eventName');

with DOM manipulation directives do:
scope.$root.$on('eventName', function(){
  $timeout(function () {
     //code
  });
});

this is a kind of 'onDigestComplete'.

No comments:

Post a Comment