AngularJS路由器对URL中无限参数的处理
嗨,我正在做我的第一个AngularJS项目。这是我现在的路线AngularJS路由器对URL中无限参数的处理,angularjs,regex,Angularjs,Regex,嗨,我正在做我的第一个AngularJS项目。这是我现在的路线 $stateProvider .state('report', { url: '/report/:Id', templateUrl: 'templates/report.html' }) 这里的问题是,/report/:reportId只处理第一级,而我的URL看起来像,/report/:val1/:val2/:val3/:val4/…等等。但它仅在URL如/report/:val1时匹
$stateProvider
.state('report', {
url: '/report/:Id',
templateUrl: 'templates/report.html'
})
这里的问题是,/report/:reportId
只处理第一级,而我的URL看起来像,/report/:val1/:val2/:val3/:val4/…
等等。但它仅在URL如/report/:val1
时匹配,之后不匹配
如何让我的URL匹配任何级别?请帮助。我自己得到了答案,当我在参数前与*一起使用时,它得到的值匹配到任何级别,但作为单个参数。例如,如果您有类似于“/report/3/0”的内容,则控制器的
$stateParams
具有3/0
。所以我们可以从那里进一步处理
$stateProvider
.state('report', {
url: '/report/*Id',
templateUrl: 'templates/report.html'
});
angular.module('app.controllers', [])
.controller('reportCtrl', function($scope, $http, $stateParams) {
console.log($stateParams);
});
上述代码将在控制台中打印“3/0”。请参考此答案。