13

I want to implement the following bootstrap select in Angular Material. How do I implement the change event shown here in bootstrap?

<select (change)="sortByProducts($event.target.value)">
  <option *ngFor="let filter of filters" [value]="filter.id">
    {{filter.title}}
  </option>
</select>

How do I add the change event to material that calls the sortByProducts function as done in the code segment shown above?

<mat-form-field>
  <mat-select>
    <mat-option *ngFor="let filter of filters" [value]="filter.id">
      {{filter.title}}
    </mat-option>
  </mat-select>
</mat-form-field>
3
  • did you try <mat-select (change)="sortByProducts"> with sortByProducts(event) in your ts file ? Commented May 6, 2019 at 15:41
  • Yes I did. Doesn't work. Commented May 6, 2019 at 15:58
  • Does this answer your question? onselected event in md-select in Angular 4 Commented Jan 31, 2024 at 9:31

1 Answer 1

31

There is a selectionChange output that you can use :

// html
<mat-select (selectionChange)="sortByProducts($event.value)">

// ts
sortByProducts(value) {
    console.log(value)
}

See https://material.angular.io/components/select/api

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.