John Dave Decano
John Dave Decano

Reputation: 128

$cookies return null when use inside a factory after redirect on angularjs

$cookies return null when use inside a factory after redirect on angularjs. Here is my controller code where i store the cookies.

    // Visitor to the cookies
    $cookieStore.put('visitor_name', $scope.name);

    $cookieStore.put('visitor_email', $scope.email);

    $cookieStore.put('visitor_message', $scope.message);

After redirect to $location.path('/client');

factory.establishUser = function() {

var data = {
    command: "establishUser",
    reqtype: "Client", //Operator or Client
    token: 'token issued',
    data: {
        userinfo: {
            token: "token",
            id: '53d4d7dda9e70788118b4567',
            hasvisited: true,
            email: $cookies.visitor_email,
            name: $cookies.visitor_name,
            usertype: "Client",
            status: "Open",
            socketkey: "socketkey"
        }
    }
};

$cookies.visitor_email and $cookies.visitor_name returns null.

Upvotes: 0

Views: 705

Answers (1)

DigitalSmile
DigitalSmile

Reputation: 26

It depends on redirect. Default implementation of cookies in Angular is storing cookie with 'path' of current location, not the root one. Currently there is no way to change this using $cookieStore.

For more information please see here.

UPDATE: According to the issue, it has been fixed and closed in 1.3.x branch.

Upvotes: 1

Related Questions