In the ngOnInit() of my Angular app, I'm subscribing to an Observable like so:
ngOnInit() {
this.loadArtistTable();
}
loadArtistTable(): void {
this._artistService.getArtists().subscribe(
(artistList) => this.artists = artistList,
(err) => console.log(err)
);
}
This is working fine as the artist details are being retrieved & displayed in a table:
<tr *ngFor="let artist of artists">
<td>{{artist.fullName}}</td>
<td>{{artist.email}}</td>
<td>{{artist.phone}}</td>
<td>{{artist.contactPreference}}</td>
<td><button class="btn btn-primary" (click)="editButtonClick(artist.id)">Edit</button></td>
</tr>
I then have a form which I use to update Artist details. After I update the details & click Save, a PUT request is sent & the Artist is updated successfully.
When I refresh the browser, the new Artist details are being displayed.
Now, I am trying to refresh the Artist table when the Save button is clicked. Here is the code executed when I click Save:
onSubmit(): void {
this.mapFormValuesToEmployeeModel();
this._artistService.updateArtist(this.artist).subscribe(
() => console.log('artist updated successfully'),
(err: any) => console.log(err)
);
this.loadArtistTable();
}
As I mentioned above, the artist is being updated, but the table is not being populated with the latest data when the button is clicked.
Can someone please tell me why this.loadArtistTable(); isn't being executed in my onSubmit() function, & a possible solution? Thanks a lot.