You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
import { Injectable } from '@angular/core';
|
|
import { BehaviorSubject } from 'rxjs';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class ModalService {
|
|
private modals: Map<string, BehaviorSubject<boolean>> = new Map();
|
|
private imageFilesSubject = new BehaviorSubject<File[] | null>(null);
|
|
private formDataSubject = new BehaviorSubject<any>(null);
|
|
|
|
getModalState(id: string): BehaviorSubject<boolean> {
|
|
if (!this.modals.has(id)) {
|
|
this.modals.set(id, new BehaviorSubject<boolean>(false));
|
|
}
|
|
return this.modals.get(id)!;
|
|
}
|
|
|
|
openModal(id: string, images?: File[], formData?: any) {
|
|
if (images) {
|
|
this.imageFilesSubject.next(images);
|
|
}
|
|
if (formData) {
|
|
this.formDataSubject.next(formData);
|
|
}
|
|
|
|
this.getModalState(id).next(true);
|
|
}
|
|
|
|
closeModal(id: string) {
|
|
this.getModalState(id).next(false);
|
|
this.imageFilesSubject.next(null);
|
|
this.formDataSubject.next(null);
|
|
}
|
|
|
|
getImageFiles(): BehaviorSubject<File[] | null> {
|
|
return this.imageFilesSubject;
|
|
}
|
|
|
|
getFormData(): BehaviorSubject<any> {
|
|
return this.formDataSubject;
|
|
}
|
|
}
|