@@ -14,7 +14,8 @@ import {
14
14
Injectable ,
15
15
OnDestroy ,
16
16
OnInit ,
17
- Output
17
+ Output ,
18
+ NgZone ,
18
19
} from '@angular/core' ;
19
20
import { Observable } from 'rxjs/Observable' ;
20
21
import { empty as observableEmpty } from 'rxjs/observable/empty' ;
@@ -50,7 +51,7 @@ const listenerOptions: any = supportsPassiveEventListeners() ? {passive: true} :
50
51
export class AutofillMonitor implements OnDestroy {
51
52
private _monitoredElements = new Map < Element , MonitoredElementInfo > ( ) ;
52
53
53
- constructor ( private _platform : Platform ) { }
54
+ constructor ( private _platform : Platform , private _ngZone : NgZone ) { }
54
55
55
56
/**
56
57
* Monitor for changes in the autofill state of the given input element.
@@ -63,6 +64,7 @@ export class AutofillMonitor implements OnDestroy {
63
64
}
64
65
65
66
const info = this . _monitoredElements . get ( element ) ;
67
+
66
68
if ( info ) {
67
69
return info . subject . asObservable ( ) ;
68
70
}
@@ -71,15 +73,17 @@ export class AutofillMonitor implements OnDestroy {
71
73
const listener = ( event : AnimationEvent ) => {
72
74
if ( event . animationName === 'mat-input-autofill-start' ) {
73
75
element . classList . add ( 'mat-input-autofilled' ) ;
74
- result . next ( { target : event . target as Element , isAutofilled : true } ) ;
76
+ this . _ngZone . run ( ( ) => result . next ( { target : event . target as Element , isAutofilled : true } ) ) ;
75
77
} else if ( event . animationName === 'mat-input-autofill-end' ) {
76
78
element . classList . remove ( 'mat-input-autofilled' ) ;
77
- result . next ( { target : event . target as Element , isAutofilled : false } ) ;
79
+ this . _ngZone . run ( ( ) => result . next ( { target : event . target as Element , isAutofilled : false } ) ) ;
78
80
}
79
81
} ;
80
82
81
- element . addEventListener ( 'animationstart' , listener , listenerOptions ) ;
82
- element . classList . add ( 'mat-input-autofill-monitored' ) ;
83
+ this . _ngZone . runOutsideAngular ( ( ) => {
84
+ element . addEventListener ( 'animationstart' , listener , listenerOptions ) ;
85
+ element . classList . add ( 'mat-input-autofill-monitored' ) ;
86
+ } ) ;
83
87
84
88
this . _monitoredElements . set ( element , {
85
89
subject : result ,
@@ -118,6 +122,7 @@ export class AutofillMonitor implements OnDestroy {
118
122
selector : '[matAutofill]' ,
119
123
} )
120
124
export class MatAutofill implements OnDestroy , OnInit {
125
+ /** Emits when the autofill state of the element changes. */
121
126
@Output ( ) matAutofill : EventEmitter < AutofillEvent > = new EventEmitter < AutofillEvent > ( ) ;
122
127
123
128
constructor ( private _elementRef : ElementRef , private _autofillMonitor : AutofillMonitor ) { }
0 commit comments