angular $location服务

来源:互联网 发布:海文网络班班代 编辑:程序博客网 时间:2024/06/05 22:32

angular $location服务

功能:获取路径,修改路径,路径跳转,url解析

实质上是对window.location一些功能的封装

功能

path():    $location.path(); // 返回当前路径,以主页面为根路径,如果在主页面就返回:'/',在别的页面可能返回: '/login'    $location.path('/login'); //路由跳转。根据配置的路由跳转到别的页面replace(): //不能返回原来的页面(在电脑上测试的不管用,不知道在手机上怎末样)    $location.path('/login')    $location.replace();    //$location.path('/login').replace()absUrl(): //获取编码后的url    //file:///C:/Users/Lenovo/Desktop/files/%E7%BD%91%E9%A1%B5%E6%96%87%E4%BB%B6/angular-1.4.0-rc.2/html/route.html#/hash(): 获取url中的hash片段host(): 获取url中的主机port(): 端口号protocal(): 协议search(): 获取或设置参数串    $location.search(); // 获取参数串。比如url:localhost//user?name=tom&age=16,方法会返回{name:"tom", age:"16"}    $location.search({name:'peter'}); //使用对象设置查询串    $location.search('name=peter&age=14'); // 字符串设置查询串url(): 获取或设置url    $location.url(); //获取页面的url    $location.url('www.gcl123.cn'); //设置url

$location多是配合路由使用

1 0
原创粉丝点击