HTML :
<div *ngIf="userdata; else blank;">
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Address</th>
<th>Role</th>
<th>Gender</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of userdata">
<td>{{data.Id}}</td>
<td>{{data.Name}}</td>
<td>{{data.Email}}</td>
<td>{{data.Address}}</td>
<td>{{data.Role}}</td>
<td>{{data.Gender}}</td>
<td>
<button type="button" (click)="setUser(data)" class="btn btn-default btn-sm edit">
<span class="glyphicon glyphicon-edit"/> Edit</button>
<button type="button" id="close" style="height: 30px;"
(click)="deleteUser(data.Id)" class="btn btn-default btn-sm close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</td>
</tr>
</tbody>
</table>
</div>
<ng-template #blank>No Records found...</ng-template>
This is what i exactly get in userdata Array :
[{
"Id": "1",
"Name": "sdfd",
"Email": "fdg",
"Address": "dfg",
"Role": "Admin",
"Gender": "male"
}, {
"Id": "2",
"Name": "dgfhh",
"Email": "gdh",
"Address": "hhh",
"Role": "User",
"Gender": "female"
}, {
"Id": "3",
"Name": "dfgf",
"Email": "fgdh",
"Address": "fghd",
"Role": "Super-Admin",
"Gender": "male"
}, "{\"blank-email\":\"Email cannot be blank\",\"blank-role\":\"You must play some role\",\"blank-gender\":\"You must specify your Gender\"}"]
so here, i don't want this to be executed from the array:
"{\"blank-email\":\"Email cannot be blank\",\"blank-role\":\"You must play some role\",\"blank-gender\":\"You must specify your Gender\"}"
You could add *ngIf
and render the elements which are not last.
<tr *ngFor="let data of userdata; last as l">
<ng-container *ngIf="!l">
.....
</ng-container>
</tr>
Rather good approach would be slice or dice down the viewModel collection itself and keep ngFor
on that collection to display it on the UI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With