- UpdateService erstellt, um asynchrone und synchrone Aktionen zu verwalten und auszuführen. - Einen Speichern-Button in der Navbar hinzugefügt, der die Ausführung aller Aktionen im UpdateService auslöst. - UpdateService in die Anwendung integriert, um die Aktualisierungslogik zu zentralisieren.
30 lines
630 B
TypeScript
30 lines
630 B
TypeScript
import { Injectable } from '@angular/core';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class UpdateService {
|
|
|
|
constructor() { }
|
|
|
|
private async_actions: Array<() => Promise<void>> = [];
|
|
private actions: Array<() => void> = [];
|
|
|
|
addAsync(action: () => Promise<void>): void {
|
|
this.async_actions.push(action);
|
|
}
|
|
|
|
add(action: () => void): void {
|
|
this.actions.push(action);
|
|
}
|
|
|
|
removeAll(): void {
|
|
this.async_actions = [];
|
|
}
|
|
|
|
async executeAll(): Promise<void> {
|
|
await Promise.all(this.async_actions.map(action => action()));
|
|
this.actions.forEach(action => action());
|
|
this.removeAll();
|
|
}
|
|
} |