片段如下
function CartForm($scope,$cookieStore) {
$scope.invoice = {
items: [{
qty: 10,
description: 'item',
cost: 9.95}]
};
//want to add the above array to cookie store here
}
如何将上述数组放入 cookiestore,然后访问它并绑定(bind)它?
最佳答案
在 cookie 中放置和获取数据的标准方法是:
输入:$cookieStore.put('invoice', $scope.invoice)
;
获取:return $cookieStore.get('invoice')
;
这将需要在您的应用程序中引用 ngCookies,以及外部 angular-cookies 脚本。见 this plunk ,查看 cookie 在控制台中的记录。
关于arrays - AngularJS将数组添加到cookie存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22470914/