使用存储的路由更改AngularJS位置

使用存储的路由更改AngularJS位置,angularjs,location,Angularjs,Location,我试图将$routeChangeStart的“next route”参数存储在服务中,并从不同的位置使用“next route”调用$location.path()。要在此澄清一些代码: $scope.$on('$routeChangeStart', function (event, next, current) { service.nextRoute = next; $rootScope.$broadcast('event:someEvent'); }); …现在我捕获事件并

我试图将$routeChangeStart的“next route”参数存储在服务中,并从不同的位置使用“next route”调用$location.path()。要在此澄清一些代码:

$scope.$on('$routeChangeStart', function (event, next, current) {
    service.nextRoute = next;
    $rootScope.$broadcast('event:someEvent');
});
…现在我捕获事件并尝试执行以下操作(假设所使用的服务都已正确注入并可用):

我得到的是一个
TypeError:Object#没有方法“charAt”
调用
$locaton.path(service.nextRoute)时出错。这里还有一个关于StackOverflow的类似问题,但建议的解决方案似乎不起作用?那么我做错了什么

谢谢

path()
获取一个字符串,其中
next
是一个
route{}
对象。听起来您实际上想捕获
$locationChangeStart
,这样您就可以访问路径了

scope.$on('$locationChangeStart', function(event, newVal, oldVal) {
});
根据这一点,这是一个未记录的特征

scope.$on('$locationChangeStart', function(event, newVal, oldVal) {
});