diff --git a/components/core/addon/string_template_outlet.ts b/components/core/addon/string_template_outlet.ts index 87e491f1ffb..6171d2d5a96 100644 --- a/components/core/addon/string_template_outlet.ts +++ b/components/core/addon/string_template_outlet.ts @@ -66,12 +66,30 @@ export class NzStringTemplateOutletDirective implements OnChanges { } } + // tslint:disable-next-line:no-any + private getType(value: string | TemplateRef): 'template' | 'string' { + if (value instanceof TemplateRef) { + return 'template'; + } else { + return 'string'; + } + } + private shouldRecreateView(changes: SimpleChanges): boolean { const { nzStringTemplateOutletContext, nzStringTemplateOutlet } = changes; - return ( - !!nzStringTemplateOutlet || - (nzStringTemplateOutletContext && this.hasContextShapeChanged(nzStringTemplateOutletContext)) - ); + let shouldOutletRecreate = false; + if (nzStringTemplateOutlet) { + if (nzStringTemplateOutlet.firstChange) { + shouldOutletRecreate = true; + } else { + const previousOutletType = this.getType(nzStringTemplateOutlet.previousValue); + const currentOutletType = this.getType(nzStringTemplateOutlet.currentValue); + shouldOutletRecreate = !(previousOutletType === 'string' && currentOutletType === 'string'); + } + } + const shouldContextRecreate = + nzStringTemplateOutletContext && this.hasContextShapeChanged(nzStringTemplateOutletContext); + return shouldContextRecreate || shouldOutletRecreate; } private hasContextShapeChanged(ctxChange: SimpleChange): boolean { @@ -102,7 +120,6 @@ export class NzStringTemplateOutletDirective implements OnChanges { ngOnChanges(changes: SimpleChanges): void { const recreateView = this.shouldRecreateView(changes); - if (recreateView) { if (this.viewContainer) { this.viewContainer.clear(); diff --git a/components/select/nz-select-top-control.component.ts b/components/select/nz-select-top-control.component.ts index 1fad6334a66..cd62485f9ef 100644 --- a/components/select/nz-select-top-control.component.ts +++ b/components/select/nz-select-top-control.component.ts @@ -63,9 +63,6 @@ export class NzSelectTopControlComponent implements OnInit, OnDestroy { } setInputValue(value: string): void { - /* if (this.inputElement) { - this.inputElement.nativeElement.value = value; - } */ this.inputValue = value; this.updateWidth(); this.nzSelectService.updateSearchValue(value); diff --git a/components/select/nz-select.component.ts b/components/select/nz-select.component.ts index 79c02278e48..3fb4d9b16f6 100644 --- a/components/select/nz-select.component.ts +++ b/components/select/nz-select.component.ts @@ -319,6 +319,7 @@ export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterVie this.onTouched(); } this.open = value; + this.nzSelectService.clearInput(); }); this.nzSelectService.check$.pipe(takeUntil(this.destroy$)).subscribe(() => { this.cdr.markForCheck(); diff --git a/components/select/nz-select.service.ts b/components/select/nz-select.service.ts index 9c0dd421619..8c0e82ec718 100644 --- a/components/select/nz-select.service.ts +++ b/components/select/nz-select.service.ts @@ -52,11 +52,7 @@ export class NzSelectService { searchValue = ''; isShowNotFound = false; // open - open$ = this.openRaw$.pipe( - distinctUntilChanged(), - share(), - tap(() => this.clearInput()) - ); + open$ = this.openRaw$.pipe(distinctUntilChanged()); activatedOption: NzOptionComponent | null; activatedOption$ = new ReplaySubject(1); listOfSelectedValue$ = this.listOfSelectedValueWithEmit$.pipe(map(data => data.value)); @@ -103,7 +99,7 @@ export class NzSelectService { // display in top control listOfCachedSelectedOption: NzOptionComponent[] = []; // selected value or ViewChildren change - valueOrOption$ = combineLatest(this.listOfSelectedValue$, this.mapOfTemplateOption$).pipe( + valueOrOption$ = combineLatest([this.listOfSelectedValue$, this.mapOfTemplateOption$]).pipe( tap(data => { this.listOfSelectedValue = data[0]; this.listOfNzOptionComponent = data[1].listOfNzOptionComponent;