angular中cookie读写方法

 时间:2026-02-14 02:30:16

1、AngularJS中对cookie的操作封装了一个单独的模块,模块名为ngCookies,若想使用需在页面中先引入angular-cookies.js:

angular中cookie读写方法

2、將ngCookies模块注入到我们自定义的模块的依赖模块中:

angular中cookie读写方法

3、ngCookies模块中有两个cookies读写相关的服务:$cookies和$cookieStroe。无论使用哪种都要先将其注入到控制器中,为了比较二者的区别,都将其注入到控制器中:

angular中cookie读写方法

1、设置cookie用put()方法:

angular中cookie读写方法

angular中cookie读写方法

2、如设置一个cookie,名为“userName”,值为“yangmin”:

angular中cookie读写方法

angular中cookie读写方法

3、获取cookie用get()方法:

angular中cookie读写方法

angular中cookie读写方法

4、如获取上面设置的“userName”:

angular中cookie读写方法

angular中cookie读写方法

5、删除cookie用remove():

angular中cookie读写方法

angular中cookie读写方法

1、1.$cookies设置的cookie值一般为字符串,$cookieStroe可用于设置字符串、对象、数组等。如图

angular中cookie读写方法

angular中cookie读写方法

2、2.$cookies可设置参数,例如可设置cookie的过期时间。$cookieStore无法设置参数

angular中cookie读写方法

  • 珍珠翡翠白玉汤(紫菜豆腐汤)的家常做法
  • 南昌室内设计培训学校、培训机构哪家好?
  • 梦三国之关平打法攻略
  • 名词解释-区际冲突法 BY浙江在线衢州频道
  • 让舌头动起来手抄报
  • 热门搜索
    北京 旅游 新疆旅游路线 四姑娘山旅游 旅游文章 南麂岛旅游攻略 许昌旅游 济州岛旅游攻略 台湾旅游签证 钦州旅游 阳泉旅游