我有以下路由配置,其中包含几个必须根据某些功能的值解析的URL。这里是代码片段:
$routeProvider
.when('/url_with_restrictions', {
templateUrl: '/pages/private/add_entity/add_gasstation.html',
controller: 'ControllerName',
// restrict angularjs routing
resolve: {
validate: functionToBeInjected(){
var validateAccess = $q.defer();
return validateAccess.promise;
}
}
})
如何定义函数functionToBeInjected()
并在控制器的每个resolve
中使用它?
答案 0 :(得分:0)
您只需提取一个功能来设置路线
function addRoute(url, template, controller) {
functionToBeInjected = ...
$routeProvider
.when(url, {
templateUrl: template,
controller: controller,
// restrict angularjs routing
resolve: {
validate: functionToBeInjected(){
var validateAccess = $q.defer();
return validateAccess.promise;
}
}
})
};