Currently, I am retrieving an observable array of custom IPix objects (Observable<IPix[]>) from a database using an API. After that, I update a record in the database by sending an edited version of the IPix object back to the API through a PUT request (based on legacyConfigTrackerId).
I am trying to figure out how to replace the original IPix object in the displayed array with the modified copy (based on legacyConfigTrackerId). This way, any changes made to the record will immediately show up in the table without needing to search or refresh.
However, I am having trouble filtering the array correctly. Every time I attempt to filter it, the result comes back as undefined and nothing gets displayed:
pixRecords$!: Observable<IPix[]>;
updatePix(pix: IPix) {
console.log('update clicked');
this.pixRecords$ =
this.pixRecords$.pipe(
map((records: IPix[]) =>
records.filter((p: IPix) => {
p.legacyConfigTrackerId !== pix.legacyConfigTrackerId
// need to do something to replace the original object in the array with the 'pix' argument
})
)
);
pix.contract.effectiveDate = this.revertEffDateFormat();
pix.contract.termDate = this.revertTermDateFormat();
this.pixService.putPix(pix);
this.formattedEffDate = '';
this.formattedTermDate = '';
this.closeModal.next(null);
}
Since I am new to Angular, my approach might be incorrect. Any suggestions would be greatly appreciated.