访问routeProvider的路径属性 [英] Access routeProvider's route properties
问题描述
对于这样定义的路由:
$routeProvider
.when('/',
{
templateUrl:'views/login.html',
controller:'Login',
private:false
});
我如何访问私人
属性 $ routeChangeStart
事件为例里面呢?
目前我使用电流。$$ route.private
来得到它,但它似乎是错误的。
How can I access the private
property inside a $routeChangeStart
event for example?
Currently I'm using current.$$route.private
to get it, but it seems wrong.
感谢。
推荐答案
这其实是<一个href=\"https://github.com/angular-ui/ui-router/wiki#attach-custom-data-to-state-objects\">recommended把与路线所有的自定义数据的数据对象作为这样的里面。
It is actually recommended to put all your custom data with routes inside a "data" object as such.
$routeProvider
.when('/',
{
templateUrl:'views/login.html',
controller:'Login',
data: {
private: false
}
});
下面是我如何访问路线PARAMS
Here is how I access route params
$rootScope.$on( "$routeChangeStart", function(event, next, current) {
next.data.private;
});
的
routeChangeStart事件的第二个参数是被称为路由对象。另一个优点是,在对象传递给孩子的数据进行任何规定。
The second parameter of the routeChangeStart event is the route object that is called. Another advantage is that anything in the data
object is passed to children states.
这篇关于访问routeProvider的路径属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!