angularjs - Make resolve in route to a reusable function -


i have lot of same code in resolve function. possible make reusable function of , pass resolve?

from this...   .when('/workers', {         resolve: {             "check": function () {                 if (!isloggedin() || !isadmin()) {                     window.location.href = '#/about';                 }             },         },         templateurl: 'html/admin/workers.html',         controller: 'adminworkerscontroller'     })    this:    .when('/workers', {             resolve: myresolvefunction()             templateurl: 'html/admin/workers.html',             controller: 'adminworkerscontroller'         }) 

you can create provider route resolve

var app = angular.module('app', []);         //must provider since injected module.config()         app.provider('routeresolver', function () {             this.$get = function () {                 return this;             };             this.route = function () {                var resolve = function () {                // resolve                 }                return {resolve: resolve};            };         });  app.config( function(routeresolverprovider) {   .when('/workers', {             resolve: routeresolverprovider.resolve()             templateurl: 'html/admin/workers.html',             controller: 'adminworkerscontroller'         }) }) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -