Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  167] [ 3]  / answers: 1 / hits: 58831  / 6 Years ago, fri, june 29, 2018, 12:00:00

I have a mat-button-toggle-group which has 5 mat-button-toggle. I need to fire an event on the click or on the change of the val, although I prefer it be a click event.



The documentation provided here shows there is no click event, but there is a change event.



I have tried the change event too (as shown below) , but the event is not getting triggered.



 <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>


In My .ts file



import {MatButtonToggleModule} from '@angular/material/button-toggle';



onValChange(val: string) {
this.selectedVal = val;
}


How to trigger the above change function?


More From » html

 Answers
18

it should be :



html:



 <mat-button-toggle-group #group=matButtonToggleGroup>
<mat-button-toggle value=raw_swift_msg (change)=onValChange($event.value) matTooltip=View Message>
<i class=fa fa-eye style=color:#455A64 aria-hidden=true></i>
</mat-button-toggle>
<mat-button-toggle (change)=onValChange($event.value) value=message_comment matTooltip=Message Comment >
<i class=fa fa-comments style=color:#455A64 aria-hidden=true></i>
</mat-button-toggle>
</mat-button-toggle-group>


component:



onValChange(value){
console.log(value)
}


check this working stackblitz


[#54089] Monday, June 25, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mackenzihannal

Total Points: 548
Total Questions: 96
Total Answers: 96

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
;