如何解析angular中的默认查询参数

时间:2014-10-31 05:04:13

标签: javascript angularjs

我想使用AngularJS读取URL查询参数的值。我使用以下网址访问HTML:

http://demo.com/demo/demo.html?param1=125&param=4

控制器:



App.controller( 'DrawsController', ['$scope','$q','$location','$http', function($scope,$q,$location,$http){
	var deferred = $q.defer();
	$http({
		url: "./api/api.php",
		method: "get",
		dataType: "json",
		params: {
			param1: $location.param1,
			param: $location.param
		}
	})
	.success(function (data, status, headers, config) {

	})
	.error(function (data, status, headers, config) {

	});
	deferred.promise;
}]);




1 个答案:

答案 0 :(得分:0)

var searchObject = $location.search();
var param1 = searchObject.param1;
var param = searchObject.param;