多个查询参数

问题描述:

我从外部服务获得的查询参数如下:多个查询参数

url/?error=someError&error_description=someErrorDescription 

我一直在试图通过这个routeProvider

$routeProvider.when('/:error', { 
     templateUrl: 'templates/user.html', 
     controller: 'MainCtrl as route' 
    }); 

捕捉到了这个在我app.js但不是一个查询参数,我需要几个在同一级别。我可以通过分割现在变成'错误'的字符串来实现,但感觉很脏。 有几个查询字符串的其他Angular解决方案吗?

+1

也许'$ location.search()'? – Chrillewoodz

因为你的路线是url/之后的一切都是你的查询。 您无法使用routeProvider处理此问题,请尝试使用$ location提供程序。

使用$位置:

angular.module('yourModule').controller('MainCtrl', function($location) { 
    this.error = $location.search()['error']; 
    this.errorDescription = $location.search()['error_description']; 
}); 

,并在user.html:

{{ route.error }} 
{{ route.errorDescription }}