diff --git a/components/auto-complete/nz-autocomplete-trigger.directive.ts b/components/auto-complete/nz-autocomplete-trigger.directive.ts index de401d5935f..9d160be0319 100644 --- a/components/auto-complete/nz-autocomplete-trigger.directive.ts +++ b/components/auto-complete/nz-autocomplete-trigger.directive.ts @@ -315,8 +315,9 @@ export class NzAutocompleteTriggerDirective implements ControlValueAccessor, OnD } private resetActiveItem(): void { - if (this.nzAutocomplete.activeItem && this.nzAutocomplete.getOptionIndex(this.nzAutocomplete.activeItem)) { - this.nzAutocomplete.setActiveItem(this.nzAutocomplete.getOptionIndex(this.nzAutocomplete.activeItem)); + const index = this.nzAutocomplete.getOptionIndex(this.nzAutocomplete.activeItem); + if (this.nzAutocomplete.activeItem && index !== -1) { + this.nzAutocomplete.setActiveItem(index); } else { this.nzAutocomplete.setActiveItem(this.nzAutocomplete.nzDefaultActiveFirstOption ? 0 : -1); } diff --git a/components/auto-complete/nz-autocomplete.component.ts b/components/auto-complete/nz-autocomplete.component.ts index 083ee7300e1..b2a9617a170 100644 --- a/components/auto-complete/nz-autocomplete.component.ts +++ b/components/auto-complete/nz-autocomplete.component.ts @@ -147,7 +147,7 @@ export class NzAutocompleteComponent implements AfterViewInit, OnDestroy { getOptionIndex(option?: NzAutocompleteOptionComponent): number { return this.options.reduce((result: number, current: NzAutocompleteOptionComponent, index: number) => { - return result === undefined ? (option === current ? index : -1) : result; + return result === -1 ? (option === current ? index : -1) : result; }, -1)!; } diff --git a/components/form/nz-form-control.component.ts b/components/form/nz-form-control.component.ts index fa1c183659e..209e46de3c4 100644 --- a/components/form/nz-form-control.component.ts +++ b/components/form/nz-form-control.component.ts @@ -40,7 +40,7 @@ import { NzFormItemComponent } from './nz-form-item.component'; export class NzFormControlComponent extends NzColDirective implements OnDestroy, OnInit, AfterContentInit, AfterViewInit, OnDestroy { private _hasFeedback = false; validateChanges: Subscription | null; - validateString: string; + validateString: string | null; controlClassMap: NgClassType = {}; iconType: string; validateControl: FormControl | null; @@ -60,11 +60,11 @@ export class NzFormControlComponent extends NzColDirective implements OnDestroy, set nzValidateStatus(value: string | FormControl | FormControlName) { if (value instanceof FormControl) { this.validateControl = value; - this.validateString = ''; + this.validateString = null; this.watchControl(); } else if (value instanceof FormControlName) { this.validateControl = value.control; - this.validateString = ''; + this.validateString = null; this.watchControl(); } else { this.validateString = value;