2016-05-30 79 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路由和它的路由提供程序。你可能有另一種解決方案。我可以自己解析這段字符串。 –