【问题标题】:AngularJS router handling of infinite params in URLAngularJS路由器处理URL中的无限参数
【发布时间】:2016-01-12 06:58:58
【问题描述】:

您好,我正在开发我的第一个 AngularJS 项目。这是我目前的路线,

  $stateProvider
    .state('report', {
      url: '/report/:Id',
      templateUrl: 'templates/report.html'
    })

这里的问题是/report/:reportId 只处理第一级,而我的 URL 看起来像 /report/:val1/:val2/:val3/:val4/... 等等。但它仅在/report/:val1 之类的 URL 时才匹配,之后则不匹配。

如何让我的网址匹配任何级别?请帮忙。

【问题讨论】:

标签: angularjs regex


【解决方案1】:

我自己得到了答案,当我在参数之前将它与 * 一起使用时,它会获得匹配任何级别但作为单个参数的值。就像如果你有类似“/report/3/0”的东西,控制器的$stateParams3/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”。

【讨论】:

    猜你喜欢
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 1970-01-01
    • 2017-06-22
    • 2023-04-01
    • 1970-01-01
    相关资源
    最近更新 更多