Search code examples
angularangular-ngselect

ng select style group headers and items


I am using ng-select (https://ng-select.github.io/ng-select#/data-sources) library in my angular project to display a drop down as follows:

<ng-select
  [items]="flattenedSelectList"
  bindLabel="displayName"
  placeholder="Select specialty"
  notFoundText="No results found. Please try a different search criteria."
  bindValue="id"
  groupBy="type"
  [(ngModel)]="selectedSpecialtyId">
</ng-select>

I want to style the group header and also the items inside each group? How can I do it?

I used the following in my .scss file but it does not seem to apply the changes. ng-optgroup for group header and ng-option-label for item.

.ng-optgroup {
  font-weight: bold;
  color: #dbe8ef;
}

.ng-option-label{
  color: red;
}

Solution

  • Use this style and add in core file style.css :

    .ng-dropdown-panel .ng-dropdown-panel-items .ng-optgroup{
      font-weight: bold;
      color: #dbe8ef;
    }
    .ng-option-label{
      color: red;
    }
    
    

    Stackblitz : https://stackblitz.com/edit/angular-ztb1ug