[英]Dynamic routing with array of values AngularJS
I would like to provide a dynamic route with AngularJS and get an array of value, like we would do with GET request parameters : (/?id[]=1&id[]=2..) I do not know if angular js provides a "clean" way like : 我想使用AngularJS提供动态路由并获取值数组,就像我们使用GET请求参数那样:(/?id [] = 1&id [] = 2 ..)我不知道angular js是否提供了一个“干净”的方式如下:
/array/of/value/[1,2,3,4]
And get the array with ngRoute and $routeProvider : 并使用ngRoute和$ routeProvider获取数组:
.when("/list/:arrayOfValue", {templateUrl: "./partials/list.html", controller: "ListController"})
If you are using ui-router
module, just inject the $state
, and use $state.params.arrayOfValue
如果您正在使用
ui-router
模块,只需注入$state
,然后使用$state.params.arrayOfValue
myModule.controller('myController', ['$state', function($state) {
var myArray = $state.params.arrayOfValue;
});
I tested it, and it's working with array of numbers or string: 我对其进行了测试,并且可以使用数字或字符串数组:
/array/of/value/[1,2,3,4]
/array/of/value/['test', 45, 'app']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.