[Fixed] Default value of ng-select


I tried to wrap ng-select into a reusable component. Everything works fine except ng-select does not display the default value.
Reproducible example here: Stackblitz

How can I get ng-select to display the default/initial value?

Thank you


In select-input.component.html you made 2 mistakes.

<ng-select #combo [ngClass]="
      controlDir && controlDir.control && controlDir.control.touched
        ? !controlDir.control.valid
          ? 'invalid-select'
          : 'valid-select'
        : null
    " placeholder="Select Type" [multiple]="multiple" [items]="items" bindLabel="{{ bindLabel }}"
    bindValue="{{ bindValue }}" [clearable]="clearable" (change)="onSelectionChange($event)" (focus)="onTouched()"

First: [(ngModel)] they call "banana in a box", so it’s always braces inside brackets and not the other way round.

Second: the term inside the double quotes must not be surrounded by braces.


Should work now.

Leave a Reply

(*) Required, Your email will not be published