在 AngularJS 路由中传递多个参数 [英] Passing multiple parameters in an AngularJS route
本文介绍了在 AngularJS 路由中传递多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试实现一个应该有多个参数的角度路线.这是我尝试过的示例:
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'
});
现在的问题是我需要总是传递 paramA 才能传递 paramB.以及 paramA 和 paramB 以传递 paramC.
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 或 paramC 吗?
Is there any way in angular where I can pass paramA, paramB or paramC independently ?
谢谢.!
推荐答案
将 $location
注入你的控制器并使用它代替 routeParams
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';
这篇关于在 AngularJS 路由中传递多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文