获取当前页地址
例如:url:http://localhost:9096/OA_Web/main.html#/workSheet/calender_leaderDetail/21
console.log($location.absUrl());
输出为:http://localhost:9096/OA_Web/main.html#/workSheet/calender_leaderDetail/21
console.log($location.url());
输出为:/workSheet/calender_leaderDetail/21
console.log($location.path());
输出为:/workSheet/calender_leaderDetail/21
console.log($location.protocol());
输出为:http
console.log($location.host());
输出为:localhost
地址裁切
var url= urls.split('/')[3].substring(1,2);
输出为:1
修改url
$location.url('/aaa'); //修改url的子路径部分(也就是当前url#后面的内容,不包括参数)
$location.search('id','111')//修改url的参数部分 第一个参数表示url参数的属性名,第二个参数是该属性名的属性值,有则修改无则添加。
$location.search({id:'55','a':'66'}) //修改多个参数
$location.search('age',null) //删除属性,有则删除
获取上一个路由地址
app.controller('calender_detail_Ctrl', ['$scope','$stateParams', '$rootScope', '$http', '$location',
function ($scope,$stateParams, $rootScope, $http, $location){
$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
$rootScope.previousState = from; //from为前一个页面的路由信息:url,cache,views,name
$rootScope.previousParams = fromParams; //fromParams为前一个页面的ID信息
$rootScope.nowState = to; //to为当前页面的路由信息:url,cache,views,name,同样,toParams为当前页面的ID信息
});
}])