There is a controller for each chart being displayed in application.
In a previous version, each controller made a separate server request to get data. But I want to combine these into a single request and share it among controllers.
So I've tried moving the request into a .run() block and then attaching response to $rootScope so all controllers can access it.
.run(['$rootScope', 'factoryName', function($rootScope, factoryName) {
factoryName.getAll().success(function(data) {
$rootScope.data = data;
});
}])
The problem is its an asynchronous request, so controllers try to load the data from $rootScope before the response comes back from server, and crashes the app.
Normally I would use resolve from $stateProvider to get the response before state load, but the application just uses angular to make the front-end dynamic, and does not have multiple states, so I would like to avoid ui.router.
Is there a way to delay loading controllers until the response comes back?