0

I have some code in Angular 6 to display data, but the code I have tried to implement does not work? My code so far:

TS file

  incident = [ 
    {id: 'E200', product: 'MP2355 Black and white', floor: '2', address: '11 Rue', code: '75019'},
  ];

  incidents = this.incident[0];

HTML file

<tr class="" *ngFor="let state of incidents">
    <td>{{state.id}}</td>
</tr>
3
  • id doesn't appear to be a property on your incidents object. Commented Feb 27, 2019 at 17:40
  • incidents = this.incident[0]; I don't get this, or the rest of the example. There is no id key in your sample data. Please update your question. Commented Feb 27, 2019 at 17:40
  • Sorry typo, the id was the serial number. Commented Feb 27, 2019 at 17:42

2 Answers 2

2
incidents = this.incident[0];

You are taking only one object from array so it can't iterate the loop in view.

this.incidents=this.incident;
<tr *ngFor= "let incident of incidents">
<td>{{ incident.id }} </td>
..
..
</tr>
Sign up to request clarification or add additional context in comments.

Comments

0

Should not that be just incident instead of incidents?

<tr class="" *ngFor="let state of incident">
    <td>{{state.id}}</td>
</tr>

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.