I was experiencing an annoying problem every time I was trying to access data I would get back from the server in an Angular.JS controller.
As it turns out, every time I shorthanded and wrote something in the essence of:
$scope.myData = Service.getMyData();Service.getMyData({}, function(d){
$scope.myData= d;
});
In my implementation I often broadcast an event of my own after the data has returned so other controllers that are dependent on this data my react accordingly:
Service.getMyData({}, function(d){
$scope.myData= d;
Context.broadcast("theDataIsReady");//shaking the $rootScope tree
});
...
$scope.$on("theDataIsReady",function(){
// a very clever snippet of code
});
// a very clever snippet of code
});
Special thanks to Ravit.
No comments:
Post a Comment
Please do not post spam on this blog, Spam sites will be reported to google.
thank you kindly.