I'm using a ngFor loop to GET a number of elements from a server.
Target: Every element has a View all button, that when is pressed I want to display the entire JSON object that has been generated by that element
Problem: When I press it, I only get the first element.
Code:
<div class="display" *ngFor="let field of fields" >
<p>Field name: {{field.name}}</p>
<p>Crop Type: {{field.Crop}}</p>
<p>Description: {{field.Description}}</p>
<button class="view" onclick="document.getElementById('ViewAll').style.display = 'block'">View all</button>
<div *ngFor="let field of fields" id="ViewAll">
<p>ID: {{field.ID}}</p>
<p>Field name: {{field.name}}</p>
<p>Crop Type: {{field.Crop}}</p>
<p>Description: {{field.Description}}</p>
<p>Others: {{field.others}}</p>
</div>
What is wrong? What have I to change?
[{"name": "Field1","Crop": "CropType","Description": "...","ID": "0"},{"name": "Field2","Crop": "CropType2","Description": "...","ID": "1"}].When i press the button on the second generated element i get the first element from JSON*ngIf="visible"in the below div in which you are showing JSON and assign it true on click of view all.