angularJs的$location的基本用法
一. 獲取url的相關方法:
以 ‘http://localhost/location.html#/foo?name=bunny#myhash’ 這個路徑爲例:
- 獲取當前完整的url路徑:
location/21.1%20$location.html#/foo?name=bunny#myhash
*2. 獲取當前url路徑(當前url#後面的內容,包括參數和哈希值):
$location.url();
// /foo?name=bunny#myhash
*3. 獲取當前url的子路徑(也就是當前url#後面的內容,不包括參數):
$location.path()
// /foo
- 獲取當前url的協議(比如http,https)
$location.protocol()
// http
- 獲取當前url的主機名
$location.host()
// localhost
- 獲取當前url的端口
$location.port()
// 80 (這裏就是wamp的默認端口號)
*7. 獲取當前url的哈希值
$location.hash()
// myhash
*8. 獲取當前url的參數的序列化json對象
$location.search()
// {“name”:“bunny”}
本文來自 城續猿的員 的CSDN 博客 ,全文地址請點擊:https://blog.csdn.net/u013184759/article/details/54138578?utm_source=copy