我有一个mat-button-toggle-group,它有5个mat-button-toggle . 我需要在点击或更改val时触发一个事件,尽管我更喜欢它是一个点击事件 .
提供的文档here显示没有点击事件,但有一个更改事件 .
我也尝试过更改事件(如下所示),但事件没有被触发 .
<mat-button-toggle-group #group="matButtonToggleGroup" [(ngModel)]="rowAction">
<mat-button-toggle value="raw_swift_msg" (change)="onValChange(value)" matTooltip="View Message">
<i class="fa fa-eye" style="color:#455A64" aria-hidden="true"></i>
</mat-button-toggle>
<mat-button-toggle value="message_comment" matTooltip="Message Comment">
<i class="fa fa-comments" style="color:#455A64" aria-hidden="true"></i>
</mat-button-toggle>
<mat-button-toggle value="link_trade" hasAccess id="LinkMessagePopup" matTooltip="Link Message">
<i class="fa fa-link" style="color:#455A64" aria-hidden="true"></i>
</mat-button-toggle>
<mat-button-toggle value="audit_trail" matTooltip="View Audit">
<i class="fa fa-history" style="color:#455A64" aria-hidden="true"></i>
</mat-button-toggle>
<mat-button-toggle hasAccess id="MessagePopup" value="move_message" matTooltip="Move message">
<i class="fa fa-exchange" style="color:#455A64" aria-hidden="true"></i>
</mat-button-toggle>
<mat-button-toggle value="log" matTooltip="View log">
<i class="fa fa-book" style="color:#455A64" aria-hidden="true"></i>
</mat-button-toggle>
</mat-button-toggle-group>
在我的.ts文件中
从'@ angular / material / button-toggle'导入;
onValChange(val: string) {
this.selectedVal = val;
}
如何触发上述更改功能?
2 回答
它应该是 :
HTML:
零件:
检查一下working stackblitz
切向相关,对于使用 fastclick 删除移动网络浏览300毫秒延迟的人来说,这是我需要做的才能让
<mat-button-toggle-group>
的change
事件触发 .说明:似乎在桌面浏览器中,mat-button-toggle 's toggleIt handler (leading to the group' s
change
dispatcher正在侦听按钮的click
事件,但在移动webview中,toggleIt处理程序正在直接侦听按钮的touchend
事件 . 某些移动Web视图在所有touchend
事件上都有内置侦听器,等待300毫秒以查看移动用户是单击还是双击,然后调度正确的click
或dblclick
事件 . Fastclick通过监听它拦截的touchend
事件来干扰它,从而永远不会调用慢速webview touchendHandler,并自行调度一次单击事件 . 但是在我们的例子中,截获的touchend
事件也不会调用toggleIt . 所以我们 turn off the interception ,赢得了't hurt the time it takes for toggleIt to get called (our UX), since the webview only delays the clickHandlers, not the mat-button-toggle'直接的touchendHandler .在main.ts
in myComponent.ts
在myComponent.html中
在myComponent.css中