源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

AngularJS的$location使用方法详解

  • 时间:2020-03-08 22:14 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:AngularJS的$location使用方法详解
[b]AngularJS的$location使用方法详解[/b] [b]一、配置config [/b]
app.config([ '$locationProvider', function($locationProvider) { 
$locationProvider.html5Mode({ 
     //设置为html5Mode(模式),当为false时为Hashbang模式 
enabled : true, 
     //是否需要加入base标签,这里设置为false,设置为true时,需在html的head配置<base href="" />标签 
requireBase : false 
}); 
} ]); 


注意:config里面的配置非常重要,不配置获取不到url里面的参数 [b]二、基本用法 [/b]
url:http://127.0.0.1:7001/liuxu/pages/main.html?name=5 
1.获取绝对路径 
$location.absUrl();  
//url:http://127.0.0.1:7001/liuxu/pages/main.html?name=5 
2.获取主机 
$location.host(); 
http://127.0.0.1 
3.获取端口号 
$location.port(); 
//7001 
4.获取文本传输协议 
$location.protocol(); 
http 
5. 获取url参数 
$location.search().name或者$location.search()['name'] 
//5 
6.获取url 
$location.url() 
//:/liuxu/pages/main.html?name=5

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部