I have a problem with $rootScope assingnment while running it on module.run.
in module run there is:
app.run(['$rootScope', 'UserData', function($rootScope, UserData) {
"use strict";
UserData.data().success(function(data) {
$rootScope.session = data;
});
}]);
then, in any controller if used early:
$scope.user = $rootScope.session;
it is undefined. if used later - it contains required data.
I guess there is race condition, as callback from UserData.data may be called after controller is initialized.
I tried to $scope.$apply and $timeout ($scope.$apply have no sense here..) on $scope.user in controller and it have me no effect.
If I try to put $scope.$apply in app.run it gaves me
digest already in progress
which is obviously true, as $http used in service by defauly calls $apply.
What am i doing wrong?
How can i provide data to all controllers in angular app? $rootScope cant work like i want, or I am doing something wrong? I see no way to update data in template/controller, so when the callback in app.run is called -data is filled.
Thanks for any help.
PS The weird thing is... when i console.log($rootScope) i see everything- even with session object with proper data, but when i try console.log($rootScope.session) its undefined.
EDIT: i found, that running $rootScope.$watch solves that issue, but its far from being DRY - putting watch in every scope variable that uses rootScope.