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 Feb 9, 2020
1 parent 0f99806 commit caed7d0
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,9 +1,10 @@
import {Injectable, Injector} from '@angular/core';
import {NgbModalRef} from './modal-ref';

/**
* Options available when opening new modal windows with `NgbModal.open()` method.
*/
export interface NgbModalOptions {
export interface NgbModalOptions<T = any> {
/**
* `aria-labelledby` attribute value to set on the modal window.
*
Expand All @@ -30,7 +31,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 @@ -97,7 +98,7 @@ export interface NgbModalOptions {
export class NgbModalConfig implements Required<NgbModalOptions> {
ariaLabelledBy: 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 @@ -89,7 +89,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 = Object.assign({}, this._config, options);
return this._modalStack.open(this._moduleCFR, this._injector, content, combinedOptions);
}
Expand Down

0 comments on commit caed7d0

Please sign in to comment.