<p class="p0">$location服务分析浏览器地址栏中的URL(基于window.location),让我们可以在应用中较为方便地使用URL里面的内容。在地址栏中更改URL,会响应到$location服务中,而在$location中修改URL,也会响应到地址栏中。
<p class="p0"> $location服务:
<span style="color: #000000">$location.url([url],[replace]);
<span style="color: #008000">//<span style="color: #008000">只能getter,返回当前url的协议(比如http,https)
<span style="color: #000000">$location.protocol();
<span style="color: #008000">//<span style="color: #008000">只能getter,返回当前url的主机名。
<span style="color: #000000">$location.host();
<span style="color: #008000">//<span style="color: #008000">只能getter,返回当前url的端口号。
<span style="color: #000000">$location.port();
<span style="color: #008000">//<span style="color: #008000">getter/setter,返回当前url的子路径(也就是当前url#后面的内容,不包括参数)
<span style="color: #000000">$location.path([path]);
<span style="color: #008000">//<span style="color: #008000">getter/setter,返回当前url的参数的序列化json对象
<span style="color: #000000">$location.search(search,[paramValue]);
<span style="color: #008000">//<span style="color: #008000">getter/setter,返回当前url的哈希值。
<span style="color: #000000">$location.hash([hash]);
<span style="color: #008000">//<span style="color: #008000">返回当前url的历史状态对象(不包括任何参数)。
<span style="color: #000000">$location.state([state]);
<span style="color: #008000">//<span style="color: #008000">如果被调用,当前$digest过程中所有$location的变化将取代当前的历史记录,而不是增加新的历史记录。
$location.replace();
<div class="cnblogs_code">
</span><span style="color: #008000">//</span><span style="color: #008000"> change the path</span>
$location.path(<span style="color: #800000">'</span><span style="color: #800000">/newValue</span><span style="color: #800000">'</span>)</pre>