简体   繁体   English

selectionChange in mat-select 不起作用 Angular 13

[英]selectionChange in mat-select not working Angular 13

I have created a mat-select with selectionChange event but when the value is changed the event is not fired.我创建了一个带有 selectionChange 事件的 mat-select,但是当值被更改时,事件没有被触发。

html file html 文件

<mat-select (selectionChange)="changeCategory()">
                    <mat-option *ngFor="let category of categoryList" [value]="category._id">{{category.name}} </mat-option> </mat-select>

ts file文件

changeCategory(){
    console.log('ok')
  }

import MatSelectModule in your app.module.ts在您的app.module.ts中导入MatSelectModule

I have prepared a working demo to show the usage of selectionChange so you can compare it with your case to see what is missing: working demo我准备了一个工作演示来展示selectionChange的用法,因此您可以将其与您的案例进行比较,看看缺少什么: 工作演示

Every time you change the selection, a number in the template is increase by 1 to show that the event is fired.每次更改选择时,模板中的数字都会增加 1,以表明事件已被触发。 I hope it helps.我希望它有所帮助。

<mat-select
            (selectionChange)="select($event)"
            required
            formControlName="adquiriente"
          >

You can try, this way你可以这样试试

select(event) {
    console.log(event.value);
    // let value = event.
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM