我的问题是关于角度路由。事实上,我在SPA应用程序上工作,第一个页面的templateUrl取决于用户角色(这些信息我在用户服务中有)。由于我无法在app.config中注入服务,我如何获得这部分中的使用角色信息来决定返回哪个url?
意思是同一条路线。when('/')我有两个或多个模板URL取决于用户角色
可以使用以下语法传递路由参数:
$routeProvider.
when('/:UserRole' {
templateUrl: 'anyPage.html',
controller: 'anyController'
});
在控制器内部(在本例中为"anyController"),可以通过注入$routeParams服务来查询路由参数:
angular.module('yourAppName')
.controller('controllerName', ['$routeParams','yourService', function($routeParams, yourService){
//call your service function with the routeParams
yourService.serviceFunction($routeParams)
}]);