replace alerts und confirms with modals #15
This commit is contained in:
34
src/app/services/popover.service.ts
Normal file
34
src/app/services/popover.service.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
// popover.service.ts
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PopoverService {
|
||||
private showPopoverSource = new Subject<{
|
||||
title: string;
|
||||
message: string;
|
||||
showInput: boolean;
|
||||
inputValue: string;
|
||||
confirmText: string;
|
||||
onConfirm: () => void;
|
||||
onCancel?: () => void;
|
||||
}>();
|
||||
|
||||
popoverState$ = this.showPopoverSource.asObservable();
|
||||
|
||||
show(options: { title: string; message: string; confirmText?: string; onConfirm?: (inputValue?: string) => void; onCancel?: () => void }) {
|
||||
this.showPopoverSource.next({
|
||||
showInput: false,
|
||||
inputValue: null,
|
||||
confirmText: 'Ok',
|
||||
onConfirm: (inputValue?: string) => {},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
showWithInput(options: { title: string; message: string; confirmText: string; inputValue: string; onConfirm: (inputValue?: string) => void; onCancel?: () => void }) {
|
||||
this.showPopoverSource.next({
|
||||
showInput: true,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user