Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I have one json file and i want to bind with some variable to show on UI.

  testjson=  {"date":1468497879354,"faulty":"F-3","mileage":"150,900 mls","search":[]}

and in html

<div>
<span>{{ testjson }}</span><--- here i am getting above json object
Date:{{date}}
Faulty:{{faulty}}
Mileage: {{mileage}}
<div>

How do i bind so that i can get perticular object value ??

share|improve this question
    
you will have to parse the json angular.fromJson – entre Jul 14 at 12:15
    
I also did with parsing i couldnt get value for perticular object testjson = JSON.parse(testjson ); this.assign =testjson .date – Sarvesh Yadav Jul 14 at 12:17
1  
simply using testjson?.date – Pardeep Jain Jul 14 at 12:23
    
I did that way but it showing me error RIGINAL EXCEPTION: TypeError: Cannot read property 'mileage' of undefined – Sarvesh Yadav Jul 14 at 12:44

You can do it like this:

<div>
<span>lala</span>
Date:{{testjson.date}}
Faulty:{{testjson.faulty}}
Mileage: {{testjson.mileage}}
<div>

https://plnkr.co/edit/eeJI0wcVTxFNlXnjXQE4?p=info

share|improve this answer
    
I did that way but it showing me error RIGINAL EXCEPTION: TypeError: Cannot read property 'mileage' of undefined – Sarvesh Yadav Jul 14 at 12:55
    
Can you please provide an example, cause as you see in plunker all works. May be you forget to fill testjson with some data? – bebebe Jul 15 at 12:10

The values may be obtained directly using string interpolation.

{{testjson.date}}
{{testjson.faulty}}

etc...

that's it :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.