在AngularJS路由中传递多个参数

时间:2021-02-06 10:59:51

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.

现在的问题是我需要总是传递paramA才能传递paramB。并且paramA和paramB为了传递paramC。

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

有角度我有什么方法可以独立传递paramA,paramB或paramC吗?

Thanks. !

1 个解决方案

#1


14  

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

将$ location注入您的控制器并使用它而不是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';

#1


14  

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

将$ location注入您的控制器并使用它而不是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';