0

I'm getting this error for array of object. My data is coming from database so I cannot change the format of the data.

Here is what my data looks like (coming from database):

dataFromDatabase:any;

this.dataFromDatabase = [
  {"startTime":"Wed Oct 18 2017 12:00:00","endTime":"Wed Oct 18 2017 12:00:00","user_id":"148"},
  {"startTime":"Thu Oct 19 2017 12:00:00","endTime":"Thu Oct 19 2017 12:00:00","user_id":"148"},
  {"startTime":"Fri Oct 20 2017 12:00:00","endTime":"Fri Oct 20 2017 12:00:00","user_id":"148"}
];

What I'm doing in template:

<div>
  <div *ngFor="let times of dataFromDatabase">
    <p>{{times.startTime}}</p>
  </div>
</div>
8
  • your code working for me man! Commented Oct 23, 2017 at 5:11
  • i'm getting this error ERROR Error: Error trying to diff Commented Oct 23, 2017 at 5:15
  • make sure that your service call returns the array of object i think its returning objects only Commented Oct 23, 2017 at 5:17
  • the above object is console.log() of the result from my service Commented Oct 23, 2017 at 5:19
  • 2
    Change this: "startTime":"Wed Oct 18 2017 12:00:00" into: startTime:"Wed Oct 18 2017 12:00:00". If you get the data from an service use JSON.parse(this.dataFromDatabase). Or use {{times["startTime"]}} in template. Commented Oct 23, 2017 at 6:42

1 Answer 1

0

This is because *ngFor expects an array but you might be getting an object from the API.Check your response and let me know if there is any other issue.

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

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.