Currently i've been playing around with angular and I am finding a hard time in how to figure it out.The problem is that I am running a $http method on app.run(). $http method get rooms from server and initialize it in $rootScope.rooms var. In controller I used this rooms variable . Since the $http method is async and sometimes it got null because the controller loaded before the method is finished . I am trying to handle it in other way .
game.js
angular.module('GameModule', [])
.run([function ("injectors...") {
$http.get("/rooms").success(function(result){
$rootScope.rooms = result;
}).error(function(error){
console.log('Error fetching rooms');
});
}])
.controller('GameCtrl', ['$scope', function ($scope) {
console.log($rootScope.rooms);
}]);
Since rooms variable will be used in others files too , i don't probably want to put $http method inside every controller unless there are no other ways. If would be nice if i could use sort of angular's service