以前传参数都是多个的key:value的形式。现在的需求是将整个对象传过去,像下面这样
然后我的写法是
/*前往订单详情页面*/
$scope.goOrderDetails=function(){
//counArr就是图片里的对象
$state.go('ticket.pay',{countArr:countArr})
}
在接收页面
var countArr=$stateParams.countArr;
console.log(countArr);
console.log(countArr.length);
结果不对了,console.log(countArr)的结果是[object object],
url也变成了127.0.0.1:9002/ticket/pay/%5Bobject%20Object%5D
我想知道是哪里的问题,之前没遇到过传一个对象的需求
高洛峰2017-05-15 17:08:33
If you want to spread it like this, you have to
$state.go('ticket.pay',{countArr: JSON.stringify(countArr)})
When picking up
var countArr = JSON.parse($stateParams.countArr)
If you want to transfer the object directly, it is recommended to use browser storage to transfer it. Please refer to this
天蓬老师2017-05-15 17:08:33
Set params in routing
. state('urlname',{
url:'urlname',
templateUrl:...,
controller:...,
params:{testObj:""}
})
In this way, the testObj taken out from the page is still an object, just use the attributes you need directly
Supplementary. . . Of course, this params can also be testObj:{}