angularjs - Loading data before loading controllers & views -


i'm having bit of trouble here.

i have angularjs application connects api , allows users login, register, etc. user receives token stored $localstorage (via ngstorage).

$localstorage[jwt] = data.token; 

when user visits application token stored, want present him loading page (regardless of page trying view) until verify token correct, , load views/controllers usual.

i've looked different ways of doing this, couldn't figure out any. pointers appreciated!

thanks.

you can use default ngroute module simple cases such this.

first configure route default resolve properties. here saying resolve should contain list of movies.

app.config(function($routeprovider){   $routeprovider.when('/',{     templateurl:'initial.html',     controller:'mainctrl'   })   .when('/two',{     templateurl: 'post.html',     controller: 'postctrl',     resolve: {       movielist: function($movies) {         return $movies.get();       }     }   })   .otherwise({     redirectto:'/'   }); }); 

secondly, interested hooking critical events of angular system. hence small example app want disable button used trigger page change, show text loading... when page change process starts...

(app.js):

app.controller('mainctrl', function($scope, $location) {   $scope.go = function() {     $location.path('/two');   };    $scope.$on('$routechangestart', function(evt){     $scope.showloading = true;     });    $scope.showloading = false;  }); 

(initial.html):

<a href="#/two" class="btn btn-default" ng-disabled="showloading">go</a> <br> <p ng-if="showloading" style="color:red">loading...</p> 

entire code here

more info ngroute


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -