且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 AngularJS 中设置 cookie 的过期日期

更新时间:2023-01-15 10:38:05

这在 1.4.0 版本的 angular 中使用 ngCookies 模块是可能的:

This is possible in the 1.4.0 build of angular using the ngCookies module:

https://docs.angularjs.org/api/ngCookies/service/$饼干

angular.module('cookiesExample', ['ngCookies'])
.controller('ExampleController', ['$cookies', function($cookies) {
  // Find tomorrow's date.
  var expireDate = new Date();
  expireDate.setDate(expireDate.getDate() + 1);
  // Setting a cookie
  $cookies.put('myFavorite', 'oatmeal', {'expires': expireDate});
}]);