Join the Stack Overflow Community
Stack Overflow is a community of 6.9 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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 – harishr Jul 14 '16 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 '16 at 12:17
1  
simply using testjson?.date – Pardeep Jain Jul 14 '16 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 '16 at 12:44
    
<div *ngIf="testjson"> – dev_in_progress Oct 24 '16 at 12:54

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 '16 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 '16 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.