File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,19 @@ describe('AutofillMonitor', () => {
137
137
autofillMonitor . stopMonitoring ( inputEl ) ;
138
138
expect ( inputEl . classlist ) . not . toContain ( 'mat-input-autofilled' ) ;
139
139
} ) ;
140
+
141
+ it ( 'should complete the stream when monitoring is stopped' , ( ) => {
142
+ const element = testComponent . input1 . nativeElement ;
143
+ const autofillStream = autofillMonitor . monitor ( element ) ;
144
+ const spy = jasmine . createSpy ( 'autofillStream complete' ) ;
145
+
146
+ autofillStream . subscribe ( undefined , undefined , spy ) ;
147
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
148
+
149
+ autofillMonitor . stopMonitoring ( element ) ;
150
+ expect ( spy ) . toHaveBeenCalled ( ) ;
151
+ } ) ;
152
+
140
153
} ) ;
141
154
142
155
describe ( 'matAutofill' , ( ) => {
Original file line number Diff line number Diff line change @@ -97,19 +97,18 @@ export class AutofillMonitor implements OnDestroy {
97
97
*/
98
98
stopMonitoring ( element : Element ) {
99
99
const info = this . _monitoredElements . get ( element ) ;
100
+
100
101
if ( info ) {
101
102
info . unlisten ( ) ;
103
+ info . subject . complete ( ) ;
102
104
element . classList . remove ( 'mat-input-autofill-monitored' ) ;
103
105
element . classList . remove ( 'mat-input-autofilled' ) ;
104
106
this . _monitoredElements . delete ( element ) ;
105
107
}
106
108
}
107
109
108
110
ngOnDestroy ( ) {
109
- this . _monitoredElements . forEach ( info => {
110
- info . unlisten ( ) ;
111
- info . subject . complete ( ) ;
112
- } ) ;
111
+ this . _monitoredElements . forEach ( ( _info , element ) => this . stopMonitoring ( element ) ) ;
113
112
}
114
113
}
115
114
@@ -119,13 +118,14 @@ export class AutofillMonitor implements OnDestroy {
119
118
selector : '[matAutofill]' ,
120
119
} )
121
120
export class MatAutofill implements OnDestroy , OnInit {
122
- @Output ( ) matAutofill = new EventEmitter < AutofillEvent > ( ) ;
121
+ @Output ( ) matAutofill : EventEmitter < AutofillEvent > = new EventEmitter < AutofillEvent > ( ) ;
123
122
124
123
constructor ( private _elementRef : ElementRef , private _autofillMonitor : AutofillMonitor ) { }
125
124
126
125
ngOnInit ( ) {
127
- this . _autofillMonitor . monitor ( this . _elementRef . nativeElement )
128
- . subscribe ( event => this . matAutofill . emit ( event ) ) ;
126
+ this . _autofillMonitor
127
+ . monitor ( this . _elementRef . nativeElement )
128
+ . subscribe ( event => this . matAutofill . emit ( event ) ) ;
129
129
}
130
130
131
131
ngOnDestroy ( ) {
You can’t perform that action at this time.
0 commit comments