这篇文章给大家分享的是有关angularJS1如何获取url中携带的参数的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
index.html 从此界面跳转到a.html界面
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>form demo</title>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<script src="js/angular.min.1.6.0.js"></script>
</head>
<body ng-app="app" ng-controller="myctrl">
<button ng-click="jump()" >点击跳转下一页</button>
<br /><br />
<a ng-href="a.html?name=xie&age=25&gender=nv" rel="external nofollow" >点击跳转下一页</a>
</div>
</body>
<script>
var app = angular.module('app', []);
app.controller('myctrl', function($scope, $window) {
$scope.jump = function() {
$window.location.href = 'a.html?name=xie&age=25&gender=nv';
}
});
</script>
</html>
a.html 跳转到的目标界面,在此界面获取url携带的参数:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<script src="js/angular.min.1.6.0.js"></script>
<title></title>
</head>
<body ng-app="myapp" ng-controller="myctrl" >
<p>a.html</p>
</body>
<script>
//Url="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);
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
}]);
app.controller('myctrl', function($scope, $location) {
console.log($location.search().name);
console.log($location.search().age);
console.log($location.search().gender);
});
//打印结果:
//[Web浏览器] "xie"
//[Web浏览器] "25"
//[Web浏览器] "nv"
</script>
</html>
感谢各位的阅读!关于“angularJS1如何获取url中携带的参数”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。