Search code examples
angular

placeholder not shown in ngselect


I'm working with ng-select in my angular form ( https://github.com/ng-select/ng-select) the code that I'm using :

<ng-select
            formControlName="model"
            name="model"
            id="add_sheet_model"
            [items]="modelItems"
            [multiple]="false"
            [searchable]="false"
            bindLabel="value"
            bindValue="id"
            placeholder="select model"
          >
          </ng-select>

the problem is that the placeholder is not displayed when I put [multiple] = "false" but when I put [multiple] = "true" the placeholder is displayed and I don't want my ngselect to be multiple.

Ps: I'm working with angular 10 and ngselect 5.0.3.

Any idea ?


Solution

  • I found the solution finally, it's not in relation to the [multiple] attribute but the way to initialize my FormGroup, this is how I initiated it:

    model: new FormControl('', [Validators.required]),
    

    well it should be like this :

    model: new FormControl(null, [Validators.required]),
    

    this issue helped me to solve this problem https://github.com/ng-select/ng-select/issues/653