【发布时间】:2019-10-15 22:18:53
【问题描述】:
我想在 Angular 7 中获取选择选项的选定值。使用 ngModel 进行双向数据绑定,我还在 app.module.ts 中导入了 FormsModule。
我的 HTML 文件:
<select (change)="selectChangeHandler($event)"
[(ngModel)]="optSelected">
<option *ngFor="let opt of options" [value]="opt.id">
{{opt.title}}
</option>
</select>
我的 TS 文件:
optSelected = 'aaa';
selectChangeHandler(event: any) {
this.optSelected = event.target.value;
console.log('The selected option is: ' + this.optSelected);
}
【问题讨论】:
标签: angular