angularjs - How to wait for resolve dependencies before rendering a template in angualr ui router state -
i need use resolved data (using resolve block) in templateurl function. how can achieve that? or can wait resolution comnplete before calling templateurl function?
here auth service need check user authenticated or not before load each view.
app.factory('appauth', function ($http, $q, $location, $cookies, redirecttourlafterlogin, myhomepage) { var self = {}; self.loginstatus= false; self.userdetails = {}; self.terminal = {}; self.monument = {}; self.loggedin = function (callback) { var deferred = $q.defer(); $http({ method: "get", url: 'rest/operator/loginstatus' }).success(function (response, status, headers, config) { if (callback) callback(response.issuccess, response.data); deferred.resolve(); }); return deferred.promise; }; self.loggedout = function(callback){ var deferred = $q.defer(); $http({ method: "post", url: 'rest/operator/logout' }).success(function (response, status, headers, config) { if (callback) callback(response.issuccess, response.data); deferred.resolve(); }); return deferred.promise; }; self.saveattempturl = function () { if ($location.path().tolowercase() != '/login') { redirecttourlafterlogin.url = $location.path(); } else { redirecttourlafterlogin.url = myhomepage.url; } }; self.redirecttoattemptedurl = function () { $location.path(redirecttourlafterlogin.url); }; return self; }); -- config section of angular use this. $routeprovider .when("/", angularamd.route({ templateurl: function (rp) { return rooturl + 'index.html'; }, controllerurl: rooturl + "indexcontroller.js", resolve: { login: function($q,appauth,$rootscope) { var deferred = $q.defer(); appauth.loggedin(function(err, data){ appauth.loginstatus = true; $rootscope.configversion = data.monument.configversion; $rootscope.monument = data.monument; if (!err) { appauth.loginstatus = false; appauth.userdetails = {}; appauth.terminal = {}; appauth.mounument = {}; deferred.resolve(); return; } if (data.user == 0) { appauth.loginstatus = false; deferred.resolve(); return; } appauth.userdetails = data.userdetails; appauth.terminal = data.model; appauth.monument = data.monument; deferred.resolve(); }); return deferred.promise; } } }))
Comments
Post a Comment