AngularJS $routeChangeSuccess 回调参数 [英] AngularJS $routeChangeSuccess callback arguments

查看:35
本文介绍了AngularJS $routeChangeSuccess 回调参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 AngularJS 的新手,对有关事件侦听器的文档感到困惑.

I'm new to AngularJS and am confused by the documentation regarding event listeners.

文档列出了 $routeChangeSuccess 事件:

The documentation lists the following for the $routeChangeSuccess event:

$routeChangeSuccess 在路由依赖项之后广播解决.ngView 监听指令来实例化控制器并渲染视图.

$routeChangeSuccess Broadcasted after a route dependencies are resolved. ngView listens for the directive to instantiate the controller and render the view.

类型:

广播目标:

根范围

然而,它没有在哪里引用传递给回调函数的任何参数.然而,我在 SO 上看到的大多数示例都有类似的回调函数列表:

However, no where does it reference any arguments that are passed to the callback function. And yet, most of the examples I've seen here on SO all have a similar callback function listing:

$rootScope.$on("$routeChangeSuccess", function(event, next, current) {
   ...
});

根据 AngularJS 文档,所有回调都将第一个参数作为 event.我明白了.但是 nextcurrent 来自哪里?在任何文档中列出的位置?

According to the AngularJS docs, all callbacks have the first argument as the event. I get that. But where are next and current coming from? Where is that listed in any of the documentation?

推荐答案

它被记录在低于 1.2 的版本中,参见这个 旧文档.但是他们似乎没有注意到他们的 broadcast 事件的回调签名丢失了.另一方面,如果你不介意从他们的 github 存储库中阅读,你可以检查这个 此处 用于 $routeChangeSuccess 回调参数.

It was documented in version less than 1.2 see this old documentation. But it seems they haven't noticed that the callback signatures for their broadcast events are missing. On the other hand, if you don't mind reading from their github repository you can check this line here for the $routeChangeSuccess callback parameters.

更新:对于 Route 对象,您实际上可以参考 $route 属性 此处记录.

Update: For the Route object you can actually refer to the $route properties documented here.

这篇关于AngularJS $routeChangeSuccess 回调参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆