【发布时间】:2019-10-12 14:27:18
【问题描述】:
这对我来说可能很可悲,但我似乎无法使用 Material css 控制台记录带有 Angular 5+ 的 Select 的选定值。长话短说,它应该做的只是返回所选选项的值并将其打印在 console.log 中
html
<mat-select (change)='filter(element)'>
<mat-option value='2018'>2018</mat-option>
<mat-option value='2017'>2017</mat-option>
<mat-option value='2016'>2016</mat-option>
<mat-option value='2015'>2015</mat-option>
</mat-select>
打字稿
filter(e:Element)
{
console.log(e)
}
任何帮助将不胜感激。
【问题讨论】:
-
尝试
selectionChange而不是change事件。<mat-select (selectionChange)='filter($event)'>。你也可以通过$event而不是element。来自文档https://material.angular.io/components/select/api -
那行得通。虽然我不得不摆脱 Element 标签,但它成功了
标签: html css angular typescript