?angular之$location基本用法
轉(zhuǎn)載:https://blog.csdn.net/u013184759/article/details/54138578
一. 獲取url的相關(guān)方法
以?'http://localhost/$location/21.1%20$location.html#/foo?name=bunny#myhash'?這個(gè)路徑為例:
1.?獲取當(dāng)前完整的url路徑:
$location.absUrl():
// http://localhost/$location/21.1%20$location.html#/foo?name=bunny#myhash
*2. 獲取當(dāng)前url路徑(當(dāng)前url#后面的內(nèi)容,包括參數(shù)和哈希值):
$location.url();
// /foo?name=bunny#myhash
*3. 獲取當(dāng)前url的子路徑(也就是當(dāng)前url#后面的內(nèi)容,不包括參數(shù)):
$location.path()
// /foo
4. 獲取當(dāng)前url的協(xié)議(比如http,https)
$location.protocol()
// http
5. 獲取當(dāng)前url的主機(jī)名
$location.host()
//localhost
6. 獲取當(dāng)前url的端口
$location.port()
// 80 (這里就是wamp的默認(rèn)端口號(hào))
*7. 獲取當(dāng)前url的哈希值
$location.hash()
// myhash
*8. 獲取當(dāng)前url的參數(shù)的序列化json對(duì)象
$location.search()
//{"name":"bunny"}