简体   繁体   中英

How to change or set cookie value with angularJS?

name of cookie "NG_TRANSLATE_LANG_KEY"

And question, how can i change value of this cookie from "ru" to another? for example to "fr" or "kk".

And i should use the angularJS.

You can use $cookie dependency injection to achieve this. There's also a ngCookie provider in angular JS 1.x

See usage above: (put and get methods)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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