1.错误原因:html中缺少了<base href="/">
2.如果html中没写,请加上
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
script代码如下:
<script>
// absUrl="http://168.33.222.69:8020/angularjs_demo/a.html#name=xie&age=25&gender=nv";
var app=angular.module("myapp",[]);
app.config(['$locationProvider', function($locationProvider) {
// $locationProvider.html5Mode(true); 使用这个时,html中加入<base href="/">
//也可以忽略次检查
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
}]);
app.controller("myctrl",function($scope,$location){
//a.html?name=xie&age=25&gender=nv
console.log('absUrl=='+$location.absUrl());
console.log('host=='+$location.host());
console.log('port=='+$location.port());
console.log('protocol=='+$location.protocol());
console.log('url=='+$location.url());
console.log('path=='+$location.path());
console.log('search=='+$location.search().name);
// 控制台打印结果
//[Web浏览器] "absUrl==http://168.33.222.69:8020/angularjs_demo/a.html#name=xie&
// age=25&gender=nv"
//[Web浏览器] "host==168.33.222.69"
//[Web浏览器] "port==8020"
//[Web浏览器] "protocol==http"
//[Web浏览器] "url==/angularjs_demo/a.html#name=xie&age=25&gender=nv"
//[Web浏览器] "path==/angularjs_demo/a.html"
//[Web浏览器] "search==undefined" 这个是什么问题??
});
</script>