【问题标题】:Change AngularJS location with stored route使用存储的路线更改 AngularJS 位置
【发布时间】:2013-08-10 16:18:31
【问题描述】:

我正在尝试将 $routeChangeStart 的“下一条路线”参数存储在服务中,并使用来自不同位置的“下一条路线”调用 $location.path()。在这里澄清一些代码:

$scope.$on('$routeChangeStart', function (event, next, current) {
    service.nextRoute = next;
    $rootScope.$broadcast('event:someEvent');
});

...现在我捕捉到事件并尝试执行类似的操作(假设所使用的服务都已正确注入且可用):

$rootScope.$on('event:someEvent', function() {
    //do some stuff
    $location.path(service.nextRoute);
});

我得到的是来自对$locaton.path(service.nextRoute); 的调用的TypeError: Object #<Object> has no method 'charAt' 错误。 StackOverflow 上还有另一个post 有类似的问题,但建议的解决方案似乎不起作用?那我做错了什么?

谢谢

【问题讨论】:

    标签: angularjs location


    【解决方案1】:

    path() 取一个字符串,其中nextroute {} 对象。听起来您实际上想捕获$locationChangeStart,这将使您能够访问路径。

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

    根据answer,这是一个未记录的功能。

    【讨论】:

      猜你喜欢
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 2015-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多