From 15563f7833eba5e6d412c4aa60131ffdaaa88423 Mon Sep 17 00:00:00 2001 From: objectisundefined <2535612040@qq.com> Date: Wed, 5 Jun 2019 18:41:46 +0800 Subject: [PATCH] refactor(module:auto-complete) change previousValue setting and fix tests (#3516) --- .../nz-autocomplete-trigger.directive.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/components/auto-complete/nz-autocomplete-trigger.directive.ts b/components/auto-complete/nz-autocomplete-trigger.directive.ts index cdae56fcf01..ee7ae0c1081 100644 --- a/components/auto-complete/nz-autocomplete-trigger.directive.ts +++ b/components/auto-complete/nz-autocomplete-trigger.directive.ts @@ -122,6 +122,7 @@ export class NzAutocompleteTriggerDirective implements ControlValueAccessor, OnD } openPanel(): void { + this.previousValue = this.elementRef.nativeElement.value; this.attachOverlay(); } @@ -178,11 +179,12 @@ export class NzAutocompleteTriggerDirective implements ControlValueAccessor, OnD handleInput(event: KeyboardEvent): void { const target = event.target as HTMLInputElement; let value: number | string | null = target.value; - if (target.type === 'number') { - value = value === '' ? null : parseFloat(value); - } - if (this.canOpen() && document.activeElement === event.target && this.previousValue !== value) { - this.previousValue = value; + + if (this.canOpen() && document.activeElement === target && this.previousValue !== value) { + if (target.type === 'number') { + value = value === '' ? null : parseFloat(value); + } + this._onChange(value); this.openPanel(); } @@ -190,7 +192,6 @@ export class NzAutocompleteTriggerDirective implements ControlValueAccessor, OnD handleFocus(): void { if (this.canOpen()) { - this.previousValue = this.elementRef.nativeElement.value; this.openPanel(); } }