Passing multiple parameters in an AngularJS route

你。 提交于 2019-12-22 06:25:09

问题


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. !


回答1:


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';


来源:https://stackoverflow.com/questions/25896675/passing-multiple-parameters-in-an-angularjs-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!