diff --git a/components/select/demo/optgroup.ts b/components/select/demo/optgroup.ts index 31933a3b74f..d3d01b41e24 100644 --- a/components/select/demo/optgroup.ts +++ b/components/select/demo/optgroup.ts @@ -3,7 +3,7 @@ import { Component } from '@angular/core'; @Component({ selector: 'nz-demo-select-optgroup', template: ` - + diff --git a/components/select/select.component.ts b/components/select/select.component.ts index 64ad3afb9b2..f402c4d698d 100644 --- a/components/select/select.component.ts +++ b/components/select/select.component.ts @@ -304,8 +304,10 @@ export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterVie /** insert group item **/ listOfGroupLabel.forEach(label => { const index = listOfContainerItem.findIndex(item => label === item.groupLabel); - const groupItem = { groupLabel: label, type: 'group', key: label } as NzSelectItemInterface; - listOfContainerItem.splice(index, 0, groupItem); + if (index > -1) { + const groupItem = { groupLabel: label, type: 'group', key: label } as NzSelectItemInterface; + listOfContainerItem.splice(index, 0, groupItem); + } }); this.listOfContainerItem = [...listOfContainerItem]; this.updateCdkConnectedOverlayPositions();