要将Angular mat-select选择的值发送到一个函数,你可以使用[(ngModel)]来绑定mat-select的值,并在值改变时触发一个函数。以下是一个示例代码:
在HTML模板中:
{{option}}
在组件中:
import { Component } from '@angular/core';
@Component({
selector: 'app-example',
templateUrl: './example.component.html',
styleUrls: ['./example.component.css']
})
export class ExampleComponent {
selectedValue: string;
options: string[] = ['Option 1', 'Option 2', 'Option 3'];
onSelectionChange(event: any) {
console.log('Selected value:', this.selectedValue);
// 在这里可以调用其他函数,并将选中的值作为参数传递
// yourFunction(this.selectedValue);
}
}
在上面的示例中,我们使用[(ngModel)]来绑定mat-select的值到组件的selectedValue属性。然后,通过(selectionChange)事件监听mat-select值的变化,并调用onSelectionChange函数。在onSelectionChange函数中,你可以访问选择的值并执行你想要的操作,比如将其传递给另一个函数。