I'm wondering about how to run post initialization code with angular. Here's my use case, I have a controller and a service, my service is performing some background task fetching data remotely and I want my controller to be alerted each time my service has received some data according to an observer pattern. Assuming my controller and my service are declared and fully ready to work, I'd like to run this kind of instructions:
angular.module('myApp.services', []);
// my controllers are here
angular.module('myApp.controllers', []);
// I'd like to do this
angular.module('myApp', ['myApp.services','myApp.controllers']).run(function(service, controller) {
service.subscribe(controller);
service.start();
// some other initialization code
});
Do you guys have any idea how to deal with that properly and if it is the good approach ?
Thx in advance for the answer and all the support brought by these google group pages