Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use cookiesProvider in angular config

I want get cookie value and set to a provider. This post https://stackoverflow.com/a/20415679/772481 mentioned $cookiesProvider. But how do I use it?

mod.config(["someProvider", "$cookiesProvider", function(someProvider, $cookiesProvider) {
    someProvider.set('configs', {'token': $cookiesProvider["XSRF-TOKEN"]})
  }]);
like image 881
angelokh Avatar asked Dec 14 '13 20:12

angelokh


1 Answers

You can inject $cookies manually:

myApp.config(function() {
  var $cookies;
  angular.injector(['ngCookies']).invoke(['$cookies', function(_$cookies_) {
    $cookies = _$cookies_;
  }]);

  // here you can use $cookies as usual
});
like image 165
Kamil Szot Avatar answered Sep 19 '22 00:09

Kamil Szot