0

I am working with MEAN.js application. I come accross one strange problem.

$scope.currentUser = Authentication.user;
console.log($scope.currentUser);

output:

    {"_id":"5579c9a4f3d71f8c2a4f1e3d","email":"[email protected]","country":"US",
"gender":"Male","name":"Ilesh Patel"}

when I execute this than it prints all the data of currentUser but as soon as I do

$scope.currentUser = Authentication.user;
console.log($scope.currentUser.name);

then I get undefined. I don't know why I am not able to get name.

0

1 Answer 1

1

I do not know AngularJs but it looks like the result is json encoded if you can output it like this to the console. Decode the result with JSON.parse before using it.

$scope.currentUser = JSON.parse(Authentication.user);
Sign up to request clarification or add additional context in comments.

Comments

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.