Add a callback on the modal closing.

This commit is contained in:
2021-08-07 10:49:42 +02:00
parent 0969f892f8
commit e53f4fd89d
3 changed files with 21 additions and 7 deletions

View File

@@ -33,11 +33,19 @@ export class CreateApplicationComponent implements OnInit {
.catch(error => console.error('An error occured while loading service types.'));
}
onServiceTypeSelection(event: ReferentialData): void {
this.form.controls.serviceType.setValue(event.value);
console.log(event.value);
}
onSubmit(): void {
if (this.form.valid) {
const appToAdd: Application = this.form.value as Application;
this._applicationService.add(appToAdd)
.then(applicationAdded => console.log('Application added.'))
.then(applicationAdded => {
console.log('Application added.');
this._modalService.close();
})
.catch(error => console.error('An error occured while adding the new application.'));
} else {
console.error('Form is invalid');
@@ -47,9 +55,4 @@ export class CreateApplicationComponent implements OnInit {
onCancel(): void {
this._modalService.close();
}
onServiceTypeSelection(event: ReferentialData): void {
this.form.controls.serviceType.setValue(event.value);
console.log(event.value);
}
}

View File

@@ -18,6 +18,11 @@ export class StatusComponent implements OnInit {
) {}
ngOnInit(): void {
this.loadApplications();
this._modalService.onClose.subscribe(() => this.loadApplications());
}
private loadApplications(): void {
this._applicationService.getAllStatus()
.then(applicationsStatus => this.applicationsStatus = applicationsStatus);
}

View File

@@ -1,11 +1,12 @@
import { Injectable, Type } from "@angular/core";
import { BehaviorSubject, Observable } from "rxjs";
import { BehaviorSubject, Observable, Subject } from "rxjs";
@Injectable({
providedIn: 'root'
})
export class ModalService {
_modalContent: BehaviorSubject<Type<unknown> | undefined> = new BehaviorSubject<Type<unknown> | undefined>(undefined);
_onClose: Subject<void> = new Subject();
open(componentClass: Type<unknown>): void {
this._modalContent.next(componentClass);
@@ -13,9 +14,14 @@ export class ModalService {
close(): void {
this._modalContent.next(undefined);
this._onClose.next();
}
get modalContent(): Observable<Type<unknown> | undefined> {
return this._modalContent.asObservable();
}
get onClose(): Observable<void> {
return this._onClose.asObservable();
}
}