我试图将$routeChangeStart的“下一个路由”参数存储在服务中,并从另一个地方用“下一个路由”调用$location.path()。为了澄清这里的一些代码:
$scope.$on('$routeChangeStart', function (event, next, current) {
service.nextRoute = next;
$rootScope.$broadcast('event:someEvent');
});...now我捕捉到事件并尝试执行类似的操作(假设所使用的服务都已正确注入并可用):
$rootScope.$on('event:someEvent', function() {
//do some stuff
$location.path(service.nextRoute);
});我得到的是调用TypeError: Object #<Object> has no method 'charAt'时出现的一个$locaton.path(service.nextRoute);错误。这里还有一个类似问题的post在StackOverflow上,但是建议的解决方案似乎不起作用吗?那我做错什么了?
谢谢
发布于 2013-08-10 16:41:02
path()接受一个字符串,其中next是route {}对象。听起来,您实际上想要捕获$locationChangeStart,这将使您能够访问路径。
scope.$on('$locationChangeStart', function(event, newVal, oldVal) {
});根据这个answer,它是一个无文档的特性。
https://stackoverflow.com/questions/18163862
复制相似问题