angularjs - Get DB Value In Angular Config -
i have app uses angular. in app.config have setup routes, want authorize routes because not uses app can see every page.
so have tried make factory gives boolean tell app if person can see route or not, , learned cannot inject factory config.
so have made provider can inject config:
(function () { 'use strict'; angular.module('services') .factory('auth', ['$http', function authfactory($http) { return { linkauth: function (name) { return $http({ method: 'get', url: '/dashboard/authorizenavitem', data: { name: name } }); } } }]); angular.module('services') .provider('authprovider', ['auth', function (auth) { var allowed = false; this.$get = function (name) { auth.linkauth(name).success(function (data) { allowed = data.authorized; }); return allowed; } }]); })();
my app.config:
(function () { 'use strict'; angular.module('app.it', []) .config(['$stateprovider', 'msnavigationserviceprovider', 'authprovider', function ($stateprovider, msnavigationserviceprovider, authprovider) { $stateprovider .state('app.it', { abstract: true, url: '/information-technology', }) .state('app.it.users', { url: '/users', views: { 'content@app': { templateurl: '/it/users', controller: 'itusercontroller vm' } } }); /* need bool if user part of group can see page. */ var allowed = true;//i want provider $get method return bool here if (allowed) { //this builds navigation bar msnavigationserviceprovider.saveitem('app.authroute', { title: 'authorized route', icon: 'icon-monitor', weight: 2 }); //this builds navigation bar msnavigationserviceprovider.saveitem('app.authroute.route', { title: 'route', state: 'app.authroute.route' }); } }]); })();
how access authprovider $get , store bool in variable in config?
Comments
Post a Comment