-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path29-location服务.html
45 lines (36 loc) · 1.19 KB
/
29-location服务.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>location服务</title>
</head>
<body>
<div ng-controller="test" >
</div>
<script type="text/javascript" src="js/angular.min.js" ></script>
<script>
var m1 = angular.module('myApp',[]);
m1.controller('test',['$scope','$location',function($scope,$location){
var a= $location.absUrl();//获取 编码后的完整的地址
//console.log(a);
//$location.path('aaa');//设置路径
//console.log($location.path());//获取路径
//$location.path('bbb').replace();//替换掉原来的路径,不能在历史记录中返回原来的路径
//hash值得设置和获取
$location.hash('hello');
//console.log($location.hash());
//搜索的设置和获取
$location.search({'age':'20'});
//console.log($location.search());
//url() 获取网址信息 路径、hash 、search值
console.log($location.url());
//host() 主机名
console.log($location.host());
//port() 端口号
console.log($location.port());
//protocol() 协议
console.log($location.protocol());
}]);
</script>
</body>
</html>