Search code examples
angularangular2-formsangular2-services

Not able to print value of object in angular2


I have an object in Angular2 as below:

userDetails = {"userId":23,"first_name":"Rajesh","last_name":"Kumar"} 

Now whenever I try to print value of userDetails.first_name in html file then there is an error on browser

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'first_name' of undefined.

Please help me to understand the root cause.


Solution

  • Your object userDetails is not Defined, that is why you are getting this error , try to console the value of userDetails & check whether it's returning empty value or not. Do share your response.