简体   繁体   English

如何使用 angularJS 更改或设置 cookie 值?

[英]How to change or set cookie value with angularJS?

name of cookie "NG_TRANSLATE_LANG_KEY" cookie 名称“NG_TRANSLATE_LANG_KEY”

And question, how can i change value of this cookie from "ru" to another?问题是,我如何将这个 cookie 的值从“ru”更改为另一个? for example to "fr" or "kk".例如“fr”或“kk”。

And i should use the angularJS.我应该使用 angularJS。

You can use $cookie dependency injection to achieve this.您可以使用 $cookie 依赖注入来实现这一点。 There's also a ngCookie provider in angular JS 1.x angular JS 1.x 中还有一个 ngCookie 提供者

See usage above: (put and get methods)见上面的用法:(put 和 get 方法)

angular.module('cookiesExample', ['ngCookies'])
.controller('ExampleController', ['$cookies', function($cookies) {
  // Retrieving a cookie
  var favoriteCookie = $cookies.get('myFavorite');
  // Setting a cookie
  $cookies.put('myFavorite', 'oatmeal');
}]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM