第8篇:angular监听和获取路由的状态

来源:互联网 发布:巨人网络总部地址 编辑:程序博客网 时间:2024/06/06 05:05

注入$location服务,使用path()方法获取路由状态和路由参数

angular.module('myApp')        .run(['$rootScope', '$location', '$routeParams', function($rootScope, $location, $routeParams) {            $rootScope.$on('$routeChangeSuccess', function(e, current, pre) {                //获取路由状态                console.log('Current route name: ' + $location.path());                // 获取路由参数                console.log($routeParams);            });        }]);


原创粉丝点击