Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing multiple parameters in an AngularJS route

I am trying to implement a angular route which should have multiple parameters. Here is an example of what I tried:

.when('/myRoute/paramA/:paramA/paramB/:paramB/paramC/:paramC', {
    templateUrl: 'abc.html',
    controller: 'pwrController as pwrCtrl'
});

Now the problem in this is that I need to always pass paramA in order to pass paramB. And paramA and paramB in order to pass paramC.

Is there any way in angular where I can pass paramA, paramB or paramC independently ?

Thanks. !

like image 353
Ateev Chopra Avatar asked Sep 17 '14 17:09

Ateev Chopra


1 Answers

inject $location into your controllers and use that instead of routeParams

var paramA = 'something';
$location.search('paramA', paramA); // write
// result http://localhost:3000/#/route/routeParam?paramA=something

$location.search() // read whole object
$location.search().paramA // read one parameter
// result 'something';
like image 131
SoluableNonagon Avatar answered Nov 05 '22 14:11

SoluableNonagon