I have an array which is returned from server and displays the items by using *ngFor in a table. After I process the selected item then I will delete it from the array. The view does not removed the deleted item automatically. However, if click on the sort function from the table header, the deleted item will be removed from the view. I know the I need to notify the view that array has been change even thought the array has been update internally. But I could not find way to make it works. I hope someone could give me a hint. Thank you.
Patient.ts
public _records: Array<CRCasesLite>;
constructor(private router: Router,
private route: ActivatedRoute) {
this._records = this.route.snapshot.data['crCasesLite'];
}
onActivateRecord(record: CRCasesLite, index: number): void {
...
if (index > -1) {
this._records.splice(index, 1);;
}
}
Patients.html
<th class="input-sm">Patient <a (click)="oby=['PatientName']" class="fa fa-caret-up fa-2x"></a> <a (click)="oby=['-PatientName']" class="fa fa-caret-down fa-2x"></a></th>
<tr *ngFor="let record of _records | orderBy : oby ? oby : ['']; let i = index; trackBy:index">
<td class="input-sm">{{record.PatientName}} {{record.Id}}</td>
<td><a class="link btn btn-primary fa fa-plus-square" (click)="onActivateRecord(record, i)"></a></td>