如何在角度 ng-select 模型中显示默认占位符?

问题描述

所以当我的表单组被加载时,我的下拉菜单看起来像这样

enter image description here

我的 ng 选择代码

 <ng-select 
     placeholder="select By Device"
     appendTo="ng-select"
     [clearable]="true"
     [searchable]="true"  
     formControlName="byDevice">
            <ng-option [value]="1">Desktop</ng-option>
            <ng-option [value]="2">Laptop</ng-option>
            <ng-option [value]="3">Tablet</ng-option>
            <ng-option [value]="4">Mobile</ng-option>  
     </ng-select>

我希望可清除选项为真,因为它的过滤器

当我点击关闭图标(可清除图标)时,我看到这样的占位符

enter image description here

基本上它在加载时应该是这样的,而不是空选项

那我该怎么做

请帮忙!!

解决方法

好的,我解决了问题,您只需为表单控件名称分配空值

  this.myForm = new FormGroup({
    'byDevice':new FormControl(null)
  });

喜欢这个

谢谢!!