I tried to get dynamic data from server to angular table but it's displaying only first row
i attached the json structure with the code
component.ts
values:any[];
this._userService.get_user_details(this._user.role_name)
.subscribe(
(data: any[]) => {
console.log('send');
console.log(data);
this.values=data;
}
)
Service
get_user_details(role: string){
return this.httpClient.post('/dashboard/api/get_user_details',{role: role});
}
<table class="table table-striped">
<thead>
<tr>
<th>YIC Id</th>
<th>Name</th>
<th>Email</th>
<th>Status</th>
<th>Controls</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let one of values ,let i = index">
<td>{{one[i]._id}}</td>
<td>{{one[i].name}}</td>
<td>{{one[i].email}}</td>
<td>{{one[i].acc}}</td>
</tr>
</tbody>
</table>
My json data
[ { _id: '1',
name: 'ranjith',
email: '[email protected]',
acc: 'y',
profile_id: 'CVRsNE73.jpg' },
{ _id: '2',
name: 'Vigne',
email: '[email protected]',
acc: 'y',
profile_id: 'Jf0qcrVL.jpg' } ]
My code
You can directly access object variable without index
<tr *ngFor="let one of values">
<td>{{one._id}}</td>
<td>{{one.name}}</td>
<td>{{one.email}}</td>
<td>{{one.acc}}</td>
</tr>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments