在Angular 6中,可以使用下面的方法来解决在selectionChange事件中无法获取选中的值的问题:
import { Component } from '@angular/core';
@Component({
selector: 'app-your-component',
templateUrl: './your-component.component.html',
styleUrls: ['./your-component.component.css']
})
export class YourComponent {
selectedValue: any;
options = [
{ label: 'Option 1', value: 1 },
{ label: 'Option 2', value: 2 },
{ label: 'Option 3', value: 3 }
];
onSelectionChange() {
console.log(this.selectedValue);
}
}
在上面的代码中,当下拉框的选中值发生改变时,ngModel会自动更新selectedValue变量的值。然后,在onSelectionChange方法中,可以通过this.selectedValue来获取选中的值。
这样就可以解决在selectionChange事件中无法获取选中的值的问题。