1

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 ??

5
  • you will have to parse the json angular.fromJson Commented Jul 14, 2016 at 12:15
  • I also did with parsing i couldnt get value for perticular object testjson = JSON.parse(testjson ); this.assign =testjson .date Commented Jul 14, 2016 at 12:17
  • 1
    simply using testjson?.date Commented Jul 14, 2016 at 12:23
  • I did that way but it showing me error RIGINAL EXCEPTION: TypeError: Cannot read property 'mileage' of undefined Commented Jul 14, 2016 at 12:44
  • <div *ngIf="testjson"> Commented Oct 24, 2016 at 12:54

2 Answers 2

2

You can do it like this:

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

Plunker Example

Sign up to request clarification or add additional context in comments.

2 Comments

I did that way but it showing me error RIGINAL EXCEPTION: TypeError: Cannot read property 'mileage' of undefined
Can you please provide an example, cause as you see in plunker all works. May be you forget to fill testjson with some data?
0

The values may be obtained directly using string interpolation.

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

etc...

that's it :)

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.