I am new to Agnular and I am trying to understand how to set and retrieve 
cookies in my application. I am successful setting and getting cookies 
using ngCookies module so far but I am stuck in a place where I can't pass 
them as a url parameter in my $resource requests. My services.js file looks 
like so:

angular.module('airlineServices', ['ngResource', 'ngCookies'])
    .factory('Airport', function($resource, $cookieStore){
        return 
$resource("http://angulairapi.rohanchhabra.in/airports/:airportCode";, {
            'auth_token': function($cookieStore){
                return $cookieStore.get('auth_token');
            }
        }, {
            query: { method: "GET", isArray: false }
        });
    })
    .factory('Flight', function($resource){
        return $resource("http://angulairapi.rohanchhabra.in/flights";);
    })
    .factory('Reservation', function($resource){
        return $resource("http://angulairapi.rohanchhabra.in/reservations/:id";);
    });

Now in the when I am setting auth_token in the URL parameters section, I am 
trying to set using a callback function.

When I return the raw value of the auth_token, it works, but when I try to 
do it dynamically by retrieving a cookie that I have stored in my browser, 
I get an error like so:

Error: $cookieStore is 
undefined.auth_token@http://localhost/angulair/js/services.js:5:5
r/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular-resource.min.js:6:487
r@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:7:390

and so on....

What am I doing wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to