3

Hi I'm working on my first AngularJS project. Here is my current route looks like,

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

The problem here is /report/:reportId is handling only the first level, whereas my URL is looking like, /report/:val1/:val2/:val3/:val4/... and so on. But it is only matching when the URL like /report/:val1 and not anything after.

How to have my URL to match any level? Please help.

Stranger
  • 10,332
  • 18
  • 78
  • 115
  • Please refer this answer. http://stackoverflow.com/questions/26692747/multiple-query-string-parameters-in-angularjs – Thangadurai Jan 12 '16 at 07:21

1 Answers1

2

I got the answer myself, when I use it with * before the params it is getting values matching up to any level but as a single parameter. Like if you have something like "/report/3/0", controller's $stateParams have 3/0. So we can handle further from there.

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

angular.module('app.controllers', [])
.controller('reportCtrl', function($scope, $http, $stateParams) {
      console.log($stateParams);
});

The above code will print "3/0" in console.

Stranger
  • 10,332
  • 18
  • 78
  • 115