Home > Web Front-end > JS Tutorial > body text

Sharing how to use $location in AngularJS

小云云
Release: 2018-01-09 10:13:23
Original
2233 people have browsed it

This article mainly introduces the relevant information about the detailed use of $location in AngularJS. I hope that through this article you can master this part of the content. Friends in need can refer to it. I hope it can help everyone.

Detailed explanation of how to use $location in AngularJS

1. Configuration config

app.config([ '$locationProvider', function($locationProvider) { 
$locationProvider.html5Mode({ 
     //设置为html5Mode(模式),当为false时为Hashbang模式 
enabled : true, 
     //是否需要加入base标签,这里设置为false,设置为true时,需在html的head配置<base href="" />标签 
requireBase : false 
}); 
} ]);
Copy after login

Note: The configuration in the config is very important. You cannot get the information in the url without configuring it. Parameters

2. Basic usage

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
Copy after login

Related recommendations:

Nginx location syntax configuration detailed explanation of location meaning $location location relocation,

Use routing and $location to switch views in angular_AngularJS

Efficiently utilize the built-in services $http, $location, etc. in Angular_AngularJS

The above is the detailed content of Sharing how to use $location in AngularJS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!