valor-software / ng2-select

Angular based replacement for select boxes
http://valor-software.github.io/ng2-select/
MIT License
675 stars 587 forks source link

Issue when we use ng2-select inside a formGroupName #925

Open xyrintech opened 6 years ago

xyrintech commented 6 years ago

Getting error when using ng2-select inside a formGroupName

TypeError: selectedItems.map is not a function at SelectComponent.set [as active] (select.js:83) at SelectComponent.writeValue (select.js:228) at eval (forms.js:2345) at eval (forms.js:3916) at Array.forEach () at FormControl.setValue (forms.js:3916) at FormControl.patchValue (forms.js:3949) at eval (forms.js:4548) at Array.forEach () at FormGroup.patchValue (forms.js:4546)

Code:

<div class="form-group col-md-12" [hidden]="!this.subAccount" formGroupName="sub_account">
                            <ng-select
                                    #activeSubAccountItem
                                    [allowClear]="true"
                                    [(items)]="subAccountItems"
                                    (selected)="subAccountSelected($event)"
                                    (removed)="subAccountRemoved($event)"
                                    placeholder="Select Parent Account"
                                    class="xtbooks-select2"
                                    [hidden]="subAccountItems === null"
                                    formControlName="id"
                                    ngbTooltip=""
                                    placement="top"
                                    triggers="manual"
                                    appInvalidTooltip>
                            </ng-select>
                            <div [hidden]="subAccountItems !== null"><label><i
                                    [class]="userSettingsService.getSpinnerClass()"></i> Loading...</label></div>
                        </div>

Removing the formGroupName makes the code to work fine.

optimistex commented 6 years ago

Hi. Try that fork: https://github.com/optimistex/ng2-select-ex It seems that the issue was solved in the fork.

xyrintech commented 6 years ago

I have tried using this but I am getting an issue with this package. I am getting an error for no provider for Dom No provider for DomSanitizer!

optimistex commented 6 years ago

Duplicate https://github.com/optimistex/ng2-select-ex/issues/4