feat(api-service): Snackbar bei erfolgreichem Update anzeigen
This commit is contained in:
parent
ae0301c5be
commit
720c25bd5c
@ -1,5 +1,7 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Observable, tap } from 'rxjs';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { inject } from '@angular/core';
|
||||
|
||||
export class ApiService<Model> {
|
||||
constructor(http: HttpClient, baseUrl: string) {
|
||||
@ -9,6 +11,7 @@ export class ApiService<Model> {
|
||||
|
||||
http: HttpClient;
|
||||
baseUrl: string;
|
||||
protected snackBar = inject(MatSnackBar);
|
||||
|
||||
getAll(): Observable<Model[]> {
|
||||
return this.http.get<Model[]>(this.baseUrl, { withCredentials: true });
|
||||
@ -25,7 +28,12 @@ export class ApiService<Model> {
|
||||
|
||||
update(updateModel: Model): Observable<Model> {
|
||||
const url = `${this.baseUrl}`;
|
||||
return this.http.put<Model>(url, updateModel, { withCredentials: true });
|
||||
return this.http.put<Model>(url, updateModel, { withCredentials: true }).pipe(
|
||||
tap(() => {
|
||||
this.snackBar.open('Aktualisierung erfolgreich!', 'Schließen', {
|
||||
duration: 2000,
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
delete(id: number): Observable<any> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user