* Close the dialog. * @param dialogResult Optional result to return to the dialog opener.
(dialogResult?: R)
| 121 | * @param dialogResult Optional result to return to the dialog opener. |
| 122 | */ |
| 123 | close(dialogResult?: R): void { |
| 124 | const closePredicate = this._config.closePredicate; |
| 125 | |
| 126 | if (closePredicate && !closePredicate(dialogResult, this._config, this.componentInstance)) { |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | this._result = dialogResult; |
| 131 | |
| 132 | // Transition the backdrop in parallel to the dialog. |
| 133 | this._containerInstance._animationStateChanged |
| 134 | .pipe( |
| 135 | filter(event => event.state === 'closing'), |
| 136 | take(1), |
| 137 | ) |
| 138 | .subscribe(event => { |
| 139 | this._beforeClosed.next(dialogResult); |
| 140 | this._beforeClosed.complete(); |
| 141 | this._ref.overlayRef.detachBackdrop(); |
| 142 | |
| 143 | // The logic that disposes of the overlay depends on the exit animation completing, however |
| 144 | // it isn't guaranteed if the parent view is destroyed while it's running. Add a fallback |
| 145 | // timeout which will clean everything up if the animation hasn't fired within the specified |
| 146 | // amount of time plus 100ms. We don't need to run this outside the NgZone, because for the |
| 147 | // vast majority of cases the timeout will have been cleared before it has the chance to fire. |
| 148 | this._closeFallbackTimeout = setTimeout( |
| 149 | () => this._finishDialogClose(), |
| 150 | event.totalTime + 100, |
| 151 | ); |
| 152 | }); |
| 153 | |
| 154 | this._state = MatDialogState.CLOSING; |
| 155 | this._containerInstance._startExitAnimation(); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Gets an observable that is notified when the dialog is finished opening. |
no test coverage detected