There seems to be no really clear documentation on using cookies with AngularJS, so I lost this a bit.
I have two controllers, one creates a cookie and saves the user ID, and then I want to get this ID later when the other controller is working. I think I successfully created the cookie and saved the value for id, however, it seems I can’t return the identifier from the cookie in the second controller. I get an error in the console when I try to read the identifier:
TypeError: 'undefined' is not an object
PS: I work in Xcode since this is an iOS app for iPhone.
function firstCtrl($scope, $cookieStore) {
$scope.connectToFacebook = function() {
FB.api('/me', function(response, data, status, headers, config) {
var fbid=response.id;
$cookieStore.put('id', fbid);
console.log($cookieStore.get('id'));
});
}
}
function secondCtrl($scope, $cookieStore) {
$scope.submit = function() {
console.log($cookieStore.get('id'));
};
}
source
share