diff --git a/components/select/nz-select.service.spec.ts b/components/select/nz-select.service.spec.ts index f87f541e474..3fdb7cb52a3 100644 --- a/components/select/nz-select.service.spec.ts +++ b/components/select/nz-select.service.spec.ts @@ -75,17 +75,20 @@ describe('SelectService', () => { it('should updateListOfTagOption work', () => { service.listOfCachedSelectedOption = [ { nzValue: `option_value_0`, nzLabel: `option_label_0` }, - { nzValue: `option_value_miss`, nzLabel: `option_label_miss` } + { nzValue: `option_value_miss`, nzLabel: `option_label_miss` }, + { nzValue: `option_value_a`, nzLabel: `option_label_a` } // tslint:disable-next-line: no-any ] as any; - service.listOfSelectedValue = [`option_value_1`, `option_value_miss_1`]; + service.listOfSelectedValue = [`option_value_1`, `option_value_miss_1`, `option_value_a`]; service.listOfTemplateOption = createListOfOption(3); service.updateListOfTagOption(); - expect(service.listOfTagOption.length).toEqual(2); + expect(service.listOfTagOption.length).toEqual(3); expect(service.listOfTagOption[0].nzValue).toEqual('option_value_miss'); expect(service.listOfTagOption[0].nzLabel).toEqual('option_label_miss'); - expect(service.listOfTagOption[1].nzValue).toEqual('option_value_miss_1'); - expect(service.listOfTagOption[1].nzLabel).toEqual('option_value_miss_1'); + expect(service.listOfTagOption[1].nzValue).toEqual('option_value_a'); + expect(service.listOfTagOption[1].nzLabel).toEqual('option_label_a'); + expect(service.listOfTagOption[2].nzValue).toEqual('option_value_miss_1'); + expect(service.listOfTagOption[2].nzLabel).toEqual('option_value_miss_1'); }); it('should updateAddTagOption work', () => { service.listOfSelectedValue = [`option_value_0`, `option_value_1`]; diff --git a/components/select/nz-select.service.ts b/components/select/nz-select.service.ts index 93c6c92d826..43dd342de64 100644 --- a/components/select/nz-select.service.ts +++ b/components/select/nz-select.service.ts @@ -182,9 +182,10 @@ export class NzSelectService { // https://github.com/NG-ZORRO/ng-zorro-antd/issues/3424 this.listOfTagOption = [...this.listOfCachedSelectedOption, ...this.listOfSelectedValue].reduce( (options: NzOptionComponent[], componentOrValue) => { + // https://github.com/NG-ZORRO/ng-zorro-antd/issues/3559 if ( typeof componentOrValue === 'string' && - !this.listOfTemplateOption.find(o => this.compareWith(o.nzValue, componentOrValue)) + ![...this.listOfTemplateOption, ...options].find(o => o.nzValue === componentOrValue) ) { const nzOptionComponent = new NzOptionComponent(); nzOptionComponent.nzValue = componentOrValue; @@ -192,7 +193,7 @@ export class NzSelectService { options.push(nzOptionComponent); } else if ( componentOrValue.nzValue && - !this.listOfTemplateOption.find(o => this.compareWith(o.nzValue, componentOrValue.nzValue)) + ![...this.listOfTemplateOption, ...options].find(o => o.nzValue === componentOrValue.nzValue) ) { options.push(componentOrValue); }