4

if i made a request on my server with $http i the the followig response:

Request URL:http://www.test.tst/login
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Cookie:JSESSIONID=349AD3AC797C6AB28121ADA1766FF4A2
Host:www.test.tst

how can i read out the "Cookie:JSESSIONID=349AD3AC797C6AB28121ADA1766FF4A2"?

thanks

2 Answers 2

6

You can use ngCookies. In order to do it, you need to include the angular-cookies.js and the ngCookie in your module.

Then you can inject $cookies and get the cookie via its get function

<script src="angular-cookies.js">

And, in your Js

angular.module('app', ['ngCookies']).controller('Test', ['$cookies', '$scope', 
    function($cookies, $scope) {
        $scope.value = $cookies.get('JSESSIONID');
    }
]);
Sign up to request clarification or add additional context in comments.

5 Comments

See other answer: $cookies does not expose a .get() method
@zewt112 Not sure what are you talking about. It's stated in the docs that you have to use the get method...
Good spot, this is a recent change for v1.4. From the docs: "BREAKING CHANGE: $cookies no longer exposes properties that represent the current browser cookie values. Now you must use the get/put/remove/etc. methods as described below." If you're using v1.3 or below, there is no .get() method
Instead of .get(), you can directly access the value using $cookies.sample = 'bar';. Seen here
(AngularJS v1.5.8) I tried the same code but not able to access cookies, my code:$timeout(function(){ $log.debug("Cookies : "); $log.debug($cookies.getAll()); $log.debug($cookies.get('JSESSIONID')); $log.debug($cookies.JSESSIONID); });
-1

$cookies does provide the .get function that is $cookieScope

If using $cookies you should just use $cookies.JSESSIONID

Angular $cookies

and

Angular $cookieStore

1 Comment

The $cookieStore service is deprecated. Read the docs that you linked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.