I'm working on AngularJs project which have top navigation items load from server using a service call
App.service('Menu', function($http){
return {
get:function(callback){
$http.get('api/menu.json').success(function(menuData){
callback(menuData);
});
}
}
});
I'm using the same in my BaseController as mentioned below
App.controller('BaseCtrl', function($scope, Menu){
$scope.menuData = {};
Menu.get(function(menuData){
$scope.menuData = menuData;
});
});
My Menu looks blank for a while until the service call succeed and assign the value to the $scope.menuData is there any way to fetch the same before rendering the view.
Please let me know, I might have tried all possible ways to do this, but nothing worked :(
PS: I'm using AngularJS v1.2.9
ng-cloakng-cloakbasically doesn't display the binding expression in the view until the bindings have actually been set, I thought that was your problem initially, it's in a way a better approach than preventing the controller/view being rendered, because in a way the latter kills the point of SPAs having almost immediate route transitions and a very fluid nature.MenuservicegetMenuPromiseshould be pointing directly to the promise in the service, it shouldn't be a function returning a promise.