@@ -18,7 +18,7 @@ import {MatBottomSheetContainer} from './bottom-sheet-container';
18
18
/**
19
19
* Reference to a bottom sheet dispatched from the bottom sheet service.
20
20
*/
21
- export class MatBottomSheetRef < T = any > {
21
+ export class MatBottomSheetRef < T = any , R = any > {
22
22
/** Instance of the component making up the content of the bottom sheet. */
23
23
instance : T ;
24
24
@@ -29,11 +29,14 @@ export class MatBottomSheetRef<T = any> {
29
29
containerInstance : MatBottomSheetContainer ;
30
30
31
31
/** Subject for notifying the user that the bottom sheet has been dismissed. */
32
- private readonly _afterDismissed = new Subject < void > ( ) ;
32
+ private readonly _afterDismissed = new Subject < R | undefined > ( ) ;
33
33
34
34
/** Subject for notifying the user that the bottom sheet has opened and appeared. */
35
35
private readonly _afterOpened = new Subject < void > ( ) ;
36
36
37
+ /** Result to be passed down to the `afterDismissed` stream. */
38
+ private _result : R | undefined ;
39
+
37
40
constructor ( containerInstance : MatBottomSheetContainer , private _overlayRef : OverlayRef ) {
38
41
this . containerInstance = containerInstance ;
39
42
@@ -54,7 +57,7 @@ export class MatBottomSheetRef<T = any> {
54
57
)
55
58
. subscribe ( ( ) => {
56
59
this . _overlayRef . dispose ( ) ;
57
- this . _afterDismissed . next ( ) ;
60
+ this . _afterDismissed . next ( this . _result ) ;
58
61
this . _afterDismissed . complete ( ) ;
59
62
} ) ;
60
63
@@ -66,21 +69,25 @@ export class MatBottomSheetRef<T = any> {
66
69
}
67
70
}
68
71
69
- /** Dismisses the bottom sheet. */
70
- dismiss ( ) : void {
72
+ /**
73
+ * Dismisses the bottom sheet.
74
+ * @param result Data to be passed back to the bottom sheet opener.
75
+ */
76
+ dismiss ( result ?: R ) : void {
71
77
if ( ! this . _afterDismissed . closed ) {
72
78
// Transition the backdrop in parallel to the bottom sheet.
73
79
this . containerInstance . _animationStateChanged . pipe (
74
80
filter ( event => event . phaseName === 'start' ) ,
75
81
take ( 1 )
76
82
) . subscribe ( ( ) => this . _overlayRef . detachBackdrop ( ) ) ;
77
83
84
+ this . _result = result ;
78
85
this . containerInstance . exit ( ) ;
79
86
}
80
87
}
81
88
82
89
/** Gets an observable that is notified when the bottom sheet is finished closing. */
83
- afterDismissed ( ) : Observable < void > {
90
+ afterDismissed ( ) : Observable < R | undefined > {
84
91
return this . _afterDismissed . asObservable ( ) ;
85
92
}
86
93
0 commit comments