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
Post a Comment