Skip to content

Commit

Permalink
fix(modal): pass modalRef as an argument into beforeDismiss callback
Browse files Browse the repository at this point in the history
  • Loading branch information
gentoo90 committed Apr 19, 2021
1 parent fe3bf5e commit e225d2a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/modal/modal-config.ts
@@ -1,10 +1,11 @@
import {Injectable, Injector} from '@angular/core';
import {NgbConfig} from '../ngb-config';
import {NgbModalRef} from './modal-ref';

/**
* Options available when opening new modal windows with `NgbModal.open()` method.
*/
export interface NgbModalOptions {
export interface NgbModalOptions<T = any> {
/**
* If `true`, modal opening and closing will be animated.
*
Expand Down Expand Up @@ -45,7 +46,7 @@ export interface NgbModalOptions {
*
* then the modal won't be dismissed.
*/
beforeDismiss?: () => boolean | Promise<boolean>;
beforeDismiss?: (modalRef: NgbModalRef<T>) => boolean | Promise<boolean>;

/**
* If `true`, the modal will be centered vertically.
Expand Down Expand Up @@ -121,7 +122,7 @@ export class NgbModalConfig implements Required<NgbModalOptions> {
ariaLabelledBy: string;
ariaDescribedBy: string;
backdrop: boolean | 'static' = true;
beforeDismiss: () => boolean | Promise<boolean>;
beforeDismiss: (modalRef: NgbModalRef<any>) => boolean | Promise<boolean>;
centered: boolean;
container: string;
injector: Injector;
Expand Down
2 changes: 1 addition & 1 deletion src/modal/modal-ref.ts
Expand Up @@ -137,7 +137,7 @@ export class NgbModalRef<T = any> {
if (!this._beforeDismiss) {
this._dismiss(reason);
} else {
const dismiss = this._beforeDismiss();
const dismiss = this._beforeDismiss(this);
if (dismiss && dismiss.then) {
dismiss.then(
result => {
Expand Down
2 changes: 1 addition & 1 deletion src/modal/modal.ts
Expand Up @@ -25,7 +25,7 @@ export class NgbModal {
*
* Also see the [`NgbModalOptions`](#/components/modal/api#NgbModalOptions) for the list of supported options.
*/
open<T>(content: T, options: NgbModalOptions = {}): NgbModalRef<T> {
open<T>(content: T, options: NgbModalOptions<T> = {}): NgbModalRef<T> {
const combinedOptions = {...this._config, animation: this._config.animation, ...options};
return this._modalStack.open(this._moduleCFR, this._injector, content, combinedOptions);
}
Expand Down

0 comments on commit e225d2a

Please sign in to comment.