2016-05-30 131 views
0

我想提供一个动态路由与AngularJS并获得一个值的数组,就像我们会做的GET请求参数:(/?id [] = 1 & id [] = 2 ..) 我不知道,如果角度JS提供了一个 “干净” 的方式,如:动态路由与值的数组AngularJS

/array/of/value/[1,2,3,4] 

而且随着ngRoute获取数组和$ routeProvider:

.when("/list/:arrayOfValue", {templateUrl: "./partials/list.html", controller: "ListController"}) 
+0

你可以在这里找到答案,你的问题:http://stackoverflow.com/questions/34601851/动态路由与阵列项目中的angularjs后过滤阵列 –

回答

0

如果使用ui-router模块,只需要注入$state,并使用$state.params.arrayOfValue

myModule.controller('myController', ['$state', function($state) { 
    var myArray = $state.params.arrayOfValue; 
}); 

我测试了它,它的工作用数字或字符串数​​组:

/array/of/value/[1,2,3,4] 
/array/of/value/['test', 45, 'app'] 
+0

感谢您的答案,但不幸的是我的应用程序不是基于ui路由器。我试图将它包含到我的应用程序,因为这似乎与我的问题有关,但我的应用程序需要ng路由和它的路由提供程序。你可能有另一种解决方案。我可以自己解析这段字符串。 –