Search code examples
angulartypescriptangular-ngselect

@ng-select/ng-select show dropdown on typing


I am using, ng-select I am having one multi-select dropdown everything working proper but i want some change, i want to show dropdown when user start types something and show only filtered data on user's typed content in text box.


Solution

  • I hope below logic can helpful,

    .HTML

    <ng-select #elem [items]="cities2"
                   bindLabel="name"
                   bindValue="id"
                   [multiple]="true"
                   placeholder="Select cities"
                   [(ngModel)]="selectedCityIds"
                   (open)="onOpen(elem)">
    

    .TS

    onOpen(elem){
     if(elem.filterInput.nativeElement.value == ""){
       elem.close();
     }
    }
    

    If you want to hide drop-down toggle ( V ), you need to add style in parent component/file.

    Index.html

    <style>
        .ng-select .ng-arrow-wrapper {
            display: none !important;
        }
    </style>