0

This route config

URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby
Route: /Chapter/:chapterId/Section/:sectionId

would result in: {chapterId:'1', sectionId:'2', search:'moby'}


Is it possible however to have a collection of objects trough $routeParams like:

 [
   {chapterId:'1', sectionId:'2', search:'moby'},
   {chapterId:'1', sectionId:'5', search:'mobydick'}
 ]

and what would be the route configuration to achieve it?

kidwon
  • 4,448
  • 5
  • 28
  • 45

2 Answers2

0

you can use $location.search()

In your example it would look like this:

var searchObject = $location.search(); // => {search: 'moby'}

You can read more about it here, they have a nice example

Asaf David
  • 3,167
  • 2
  • 22
  • 38
0

I found a somewhat solution myself:

url:

domain#/foo/whatever?id=1&id=2&name=Moo&name=Boo

route config

$routeProvider.when('/foo/whatever', {
  templateUrl: 'whatever.html',
  controller: 'WhatEverCtrler'
});

controller:

module.controller('WhatEverCtrler',['$routeParams', function ($routeParams) {
  console.log('routeParams: ', $routeParams);
  // logs --> Object {id: Array[2], name: Array[2]}
}]);
kidwon
  • 4,448
  • 5
  • 28
  • 45