angular.js - angularjs url passes an object
给我你的怀抱
给我你的怀抱 2017-05-15 17:06:33
0
3
785

Previously, the pass parameters were in the form of multiple key:value. The current requirement is to pass the entire object, like the following

Then my writing method is

                 /*前往订单详情页面*/
                $scope.goOrderDetails=function(){
                //counArr就是图片里的对象
                    $state.go('ticket.pay',{countArr:countArr})
                } 
                

On the receiving page

var countArr=$stateParams.countArr;
                console.log(countArr);
                console.log(countArr.length);

The result is wrong, the result of console.log(countArr) is [object object],
url also becomes 127.0.0.1:9002/ticket/pay/[object Object]
I think I know what the problem is. I have never encountered the need to pass an object before

给我你的怀抱
给我你的怀抱

reply all(3)
小葫芦

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

阿神

Do I need to convert it to json first?

Peter_Zhu

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:{}

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template