将其从更改更改为选择更改
。
<mat-select (change)="doSomething($event)">
现在
<mat-select (selectionChange)="doSomething($event)">
https://material.angular.io/components/select/api
如果你使用的是反应式表单,你可以像这样监听选择控件的变化..
this.form.get('mySelectControl').valueChanges.subscribe(value => { ... do stuff ... })
对于:
1)mat-select < code >(selection change)= " my function()" 在angular中的工作方式如下:
sample.component.html
<mat-select placeholder="Select your option" [(ngModel)]="option" name="action"
(selectionChange)="onChange()">
<mat-option *ngFor="let option of actions" [value]="option">
{{option}}
</mat-option>
</mat-select>
sample.component.ts
actions=['A','B','C'];
onChange() {
//Do something
}
2)简单的html选择(更改)="myFunction()"
在角度上工作为:
sample.component.html
<select (change)="onChange()" [(ngModel)]="regObj.status">
<option>A</option>
<option>B</option>
<option>C</option>
</select>
sample.component.ts
onChange() {
//Do something
}