Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS路由器对URL中无限参数的处理_Angularjs_Regex - Fatal编程技术网

AngularJS路由器对URL中无限参数的处理

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时匹

嗨,我正在做我的第一个AngularJS项目。这是我现在的路线

  $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”。

请参考此答案。