0

how to binding this data

    export const CEK: Cek[] = [
  {
    id : 1,
    name : 'one',
    arr : [{lat : 123, long:3212}]
  },
  {
    id : 2,
    name : 'two',
    arr : [{lat : 123, long:3212}]
  },
];

i have try binding data like this

<tr *ngFor="let data of datacek">
        <td> {{data.id}} </td>
        <td> {{data.name}}</td>
        <td> {{data.arr[lat]}} {{data.arr[long]}} </td>
    </tr>

^ data.arr[lat] or data.arr[lat] is not showing anything

or i have try this way

<tr *ngFor="let data of datacek">
        <td> {{data.id}} </td>
        <td> {{data.name}}</td>
        <td> {{data.arr}}</td>
    </tr>

and the result only showing [object Object]

any idea how to binding my case of data ?

2
  • 2
    What is datacek? Commented Jan 9, 2018 at 10:13
  • yes i think it shoudl be Cek! Commented Jan 9, 2018 at 10:14

3 Answers 3

3

Use arr property as object then it will work with your existing templating.

export const CEK: Cek[] = [
  {
    id : 1,
    name : 'one',
    arr : {lat : 123, long:3212}
  },
  {
    id : 2,
    name : 'two',
    arr : {lat : 123, long:3212}
  },
];

Otherwise use index for arr array

<td> {{data.arr[0].lat}} {{data.arr[0].long}} </td>

You declared the property as array and using it like an object. This is the problem.

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

1 Comment

Please accept the answer if it works @ShaugiMuhammad
1

it should be:

<td> {{data.arr[0].lat}} {{data.arr[0].long}} </td>

Comments

1

Use following code:

<tr *ngFor="let data of datacek">
    <td> {{data.id}} </td>
    <td> {{data.name}}</td>
    <td> {{data.arr[0].lat}} {{data.arr[0].long}} </td>
</tr>

Let me know is it solved your issue.

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.