feat(ngModel):handle ime events (#13891)

PR Close: #13891
This commit is contained in:
执衡
2017-01-12 20:02:45 +08:00
committed by Miško Hevery
parent c7245189e2
commit c5ea03a023
3 changed files with 47 additions and 2 deletions
@@ -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 {