@@ -19,6 +19,7 @@ import {
19
19
OnInit ,
20
20
Optional ,
21
21
Self ,
22
+ NgZone ,
22
23
} from '@angular/core' ;
23
24
import { FormGroupDirective , NgControl , NgForm } from '@angular/forms' ;
24
25
import { CanUpdateErrorState , ErrorStateMatcher , mixinErrorState } from '@angular/material/core' ;
@@ -218,7 +219,8 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl<
218
219
@Optional ( ) _parentFormGroup : FormGroupDirective ,
219
220
_defaultErrorStateMatcher : ErrorStateMatcher ,
220
221
@Optional ( ) @Self ( ) @Inject ( MAT_INPUT_VALUE_ACCESSOR ) inputValueAccessor : any ,
221
- private _autofillMonitor : AutofillMonitor ) {
222
+ private _autofillMonitor : AutofillMonitor ,
223
+ ngZone : NgZone ) {
222
224
super ( _defaultErrorStateMatcher , _parentForm , _parentFormGroup , ngControl ) ;
223
225
// If no input value accessor was explicitly specified, use the element as the input value
224
226
// accessor.
@@ -233,15 +235,18 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl<
233
235
// key. In order to get around this we need to "jiggle" the caret loose. Since this bug only
234
236
// exists on iOS, we only bother to install the listener on iOS.
235
237
if ( _platform . IOS ) {
236
- _elementRef . nativeElement . addEventListener ( 'keyup' , ( event : Event ) => {
237
- let el = event . target as HTMLInputElement ;
238
- if ( ! el . value && ! el . selectionStart && ! el . selectionEnd ) {
239
- // Note: Just setting `0, 0` doesn't fix the issue. Setting `1, 1` fixes it for the first
240
- // time that you type text and then hold delete. Toggling to `1, 1` and then back to
241
- // `0, 0` seems to completely fix it.
242
- el . setSelectionRange ( 1 , 1 ) ;
243
- el . setSelectionRange ( 0 , 0 ) ;
244
- }
238
+ ngZone . runOutsideAngular ( ( ) => {
239
+ _elementRef . nativeElement . addEventListener ( 'keyup' , ( event : Event ) => {
240
+ let el = event . target as HTMLInputElement ;
241
+ if ( ! el . value && ! el . selectionStart && ! el . selectionEnd ) {
242
+ // Note: Just setting `0, 0` doesn't fix the issue. Setting
243
+ // `1, 1` fixes it for the first time that you type text and
244
+ // then hold delete. Toggling to `1, 1` and then back to
245
+ // `0, 0` seems to completely fix it.
246
+ el . setSelectionRange ( 1 , 1 ) ;
247
+ el . setSelectionRange ( 0 , 0 ) ;
248
+ }
249
+ } ) ;
245
250
} ) ;
246
251
}
247
252
0 commit comments