AngularJS cookie与数组

时间:2018-03-05 08:09:28

标签: javascript angularjs cookies

我像这样发送我的数据

love.graphics.scale(math.floor(0.3*2048)/2048) obj和$cookies.putObject("currentLocation,values,allLocList", obj, vm.tempData, vm.allLocationList);vm.tempData。但是objects是包含JSON对象的数组。

在我的状态文件中,我使用

获取数据
vm.allLocationList

然后当我去控制器时, resolve: { entity: function($cookies) { return { location: $cookies.getObject("currentLocation"), values: $cookies.getObject("values"), allLocationList: $cookies.getObject("allLocList") }; } } 是okey,entity.location是okey但entity.values未定义。你有什么想法吗?

1 个答案:

答案 0 :(得分:1)

应该是$cookies.putObject(key, value, [options]); - $cookies documentation

逐个设置您的值(键,值):

$cookies.putObject("currentLocation",obj);
$cookies.putObject("values", vm.tempData);
$cookies.putObject("allLocList", vm.allLocationLis);

获取您的值

resolve: {
  entity: function($cookies) {
    return {
      location: $cookies.getObject("currentLocation"),
      values: $cookies.getObject("values"),
      allLocationList: $cookies.getObject("allLocList")
    };
  }
}

<强>&GT; Demo fiddle