0

I'm trying to change the background color of my mat-select option or the div container using ngClass in Angular 8 whenever I changed the value, followed the documentation and some samples but they only worked on list, the results which I want is not working when I try mat-select.

here'is my html code

<div class="status">  
<mat-select matTooltip="Update your progress"
            (selectionChange)="updateStatus($event,listtask)"
            [(ngModel)]="listtask.status">

  <mat-option *ngFor="let status of status" 
              [value]="status" 
              [ngClass]="
              {
                'selectbg1':status=='Not Yet Started',
                'selectbg2':status=='In Progress',
                'selectbg3':status=='Done'
              }">
  </mat-option>

</mat-select>
</div>

CSS

.selectbg1{
  background:red;
}

.selectbg2{
  background:orange;
}

.selectbg3{
  background:green;
}

TS Component

export class TasklistComponent implements OnInit {
  //status array
  status = ['Not Yet Started','Working on It','On Going','Almost There','Done'];
  selectedStatus:string;
}
Hsuan Lee
  • 2,300
  • 1
  • 10
  • 18
Carlo A
  • 117
  • 9

1 Answers1

0

You will need to target the span inside the mat option

.selectbg1 span {
  background:red;
}

.selectbg2 span {
  background:orange;
}

.selectbg3 span {
  background:green;
}
Adrian Brand
  • 20,384
  • 4
  • 39
  • 60