Access routeProvider's route properties

前端 未结 2 982
耶瑟儿~
耶瑟儿~ 2021-02-06 02:10

For a route defined like this:

$routeProvider
.when(\'/\',
{
    templateUrl:\'views/login.html\',
    controller:\'Login\',
    private:false
});
2条回答
  •  执念已碎
    2021-02-06 02:53

    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
        }
    });
    

    Here is how I access route params

    $rootScope.$on( "$routeChangeStart", function(event, next, current) {
       next.data.private;
    });
    

    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.

提交回复
热议问题