@@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Directive, Host, Inject, Input, OnChanges, OnDestroy, Optional, Output, Self, SimpleChanges, forwardRef} from '@angular/core';
|
||||
import {Directive, Host, HostListener, Inject, Input, OnChanges, OnDestroy, Optional, Output, Self, SimpleChanges, forwardRef} from '@angular/core';
|
||||
|
||||
import {EventEmitter} from '../facade/async';
|
||||
import {FormControl} from '../model';
|
||||
@@ -115,6 +115,7 @@ export class NgModel extends NgControl implements OnChanges,
|
||||
_control = new FormControl();
|
||||
/** @internal */
|
||||
_registered = false;
|
||||
private _composing = false;
|
||||
viewModel: any;
|
||||
|
||||
@Input() name: string;
|
||||
@@ -124,6 +125,15 @@ export class NgModel extends NgControl implements OnChanges,
|
||||
|
||||
@Output('ngModelChange') update = new EventEmitter();
|
||||
|
||||
@HostListener('compositionstart')
|
||||
compositionStart(): void { this._composing = true; }
|
||||
|
||||
@HostListener('compositionend')
|
||||
compositionEnd(): void {
|
||||
this._composing = false;
|
||||
this.update.emit(this.viewModel);
|
||||
}
|
||||
|
||||
constructor(@Optional() @Host() parent: ControlContainer,
|
||||
@Optional() @Self() @Inject(NG_VALIDATORS) validators: Array<Validator|ValidatorFn>,
|
||||
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: Array<Validator|AsyncValidatorFn>,
|
||||
@@ -167,7 +177,7 @@ export class NgModel extends NgControl implements OnChanges,
|
||||
|
||||
viewToModelUpdate(newValue: any): void {
|
||||
this.viewModel = newValue;
|
||||
this.update.emit(newValue);
|
||||
!this._composing && this.update.emit(newValue);
|
||||
}
|
||||
|
||||
private _setUpControl(): void {
|
||||
|
||||
Reference in New Issue
Block a user