This question has been revised since this morning.
I am working with two distinct modules, 'admin' and 'authorization'. Within the provider block of the authorization module, I utilize $routeProvider
to add an identical route to all route definitions.
Let's start with admin.js:
angular.module('authorization', [])
.provider('$appRoute', function () {
this.$get = function($routeProvider) {
var universalResolves = {authorize: function($authorization) {
return $authorization.authorize();
}};
var extendedRouter = angular.extend({}, $routeProvider, {
when: function(path, route) {
route.resolve = (route.resolve) ? route.resolve : {};
angular.extend(route.resolve, universalResolves);
$routeProvider.when(path, route);
return this;
}
});
return new extendedRouter();
}
})
.factory('$authorization', ['$http', '$location', function($http, $location) {
var $authorization = {};
$authorization.authorize = function() {
var path = $location.path();
return promise = $http.get('/svc/authorize/view?urlPath=' + path).then(function(response) {
var data = response.data;
if (response.data.result === 'NOT_AUTHORIZED') {
throw "NOT_AUTHORIZED";
}
return data;
});
};
return $authorization;
}]);
Now let's move on to my admin module:
angular.module('admin', ['ngRoute', 'ngSanitize', 'ngCsv'
, 'authorization'
])
.controller('mainCtrl', function() {
})
.config(['$routeProvider', '$appRouteProvider', function($routeProvider, $appRouteProvider) {
// The previous definition that needs to be updated to use $appRouteProvider
$routeProvider.when('/login', {
templateUrl: '/login/auth.html',
controller: 'loginCtrl'
});
$appRouteProvider.when('/page', {
templateUrl: 'page.tmpl.html',
controller: 'pageCtrl'
});
Unfortunately, an error occurs:
Error: [$injector:modulerr] Failed to instantiate module app due to:
$appRouteProvider.when is not a function
@https://localhost:8443/admin.js:87:9
invoke@https://localhost:8443/js/angular/angular.js:4718:16
runInvokeQueue@https://localhost:8443/js/angular/angular.js:4611:11
loadModules/<@https://localhost:8443/js/angular/angular.js:4620:11
forEach@https://localhost:8443/js/angular/angular.js:321:11
loadModules@https://localhost:8443/js/angular/angular.js:4601:5
loadModules/<@https://localhost:8443/js/angular/angular.js:4618:40
forEach@https://localhost:8443/js/angular/angular.js:321:11
loadModules@https://localhost:8443/js/angular/angular.js:4601:5
createInjector@https://localhost:8443/js/angular/angular.js:4523:19
doBootstrap@https://localhost:8443/js/angular/angular.js:1758:20
bootstrap@https://localhost:8443/js/angular/angular.js:1779:12
angularInit@https://localhost:8443/js/angular/angular.js:1664:5
@https://localhost:8443/js/angular/angular.js:31763:5
j@https://localhost:8443/js/jquery/jquery.min.js:2:29566
g/</k<@https://localhost:8443/js/jquery/jquery.min.js:2:29882
The $appRouteProvider is being recognized, but only the this.$get()
method. Can anyone provide assistance?