AngularJS当前路径?
这听起来可能很奇怪,但我需要检查控制器中的当前路由路径。我找不到答案 我有3条路线:默认“/”、“报告”和“预览” 如何在控制器中检查路线AngularJS当前路径?,angularjs,Angularjs,这听起来可能很奇怪,但我需要检查控制器中的当前路由路径。我找不到答案 我有3条路线:默认“/”、“报告”和“预览” 如何在控制器中检查路线 constructor( private dataService: DataService, private $scope: ng.IScope, private $location: ng.ILocationService, private $route, // what type s
constructor(
private dataService: DataService,
private $scope: ng.IScope,
private $location: ng.ILocationService,
private $route, // what type should it be (for typescript)?
private $routeParams: IRouteParams,
private $log: ng.ILogService) {
var xxx = $route.current; // doesnt work, undefined always
}
$location
服务有两种方法,您可以使用$location.path()
和$location.url()
AngularJS文档应足够清晰:
- -返回当前路由的当前路径
- -返回完整的url
$location
服务有两种方法,您可以使用$location.path()
和$location.url()
AngularJS文档应足够清晰:
- -返回当前路由的当前路径
- -返回完整的url
$route
类型是private$route:IRouteService
,它有一个可选属性current
。除了@AlexanderStaroselsky,您还需要安装角度路由打字,以便通过ng.route.IRouteService
可以使用IRouteService
接口$routeParams
实际上可以通过ng.route.IRouteParamsService
@Alexander Staroselsky获得,是的,谢谢。那么这是Angular还是Angular 2.x?这一点非常重要。您要查找的$route
类型是private$route:IRouteService
,它有一个可选属性current
。除了@AlexanderStaroselsky,您还需要安装角度路由打字,以便通过ng.route.IRouteService
可以使用IRouteService
接口<代码>$routeParams实际上可以通过ng.route.IRouteParamsService
@Alexander Staroselsky获得,是的,谢谢。