我正在尝试使用以下代码将resolve参数动态地附加到我所有已定义的路由上:
// attach resolve to each route programatically
var originalWhen = $routeProvider.when;
$routeProvider.when = function(path, route) {
if (path !== '/login') {
route.resolve || (route.resolve = {});
angular.extend(route.resolve, {
authorize: function($http) {
console.log("authorize test");
return $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 originalWhen.call($routeProvider, path, route);
}
}
不幸的是,访问路由时,$http.get()
永远不会触发。谁能帮我吗?