Issue
here is my html file
<mat-radio-group formControlName="select1" (click)="onSearchChange($event.target.value)" >
<mat-radio-button formControlName="select1" value=post1 ngDefaultControl >
{{post1}}
per post
</mat-radio-button>
<br><br>
<mat-radio-button formControlName="select1" value=story ngDefaultControl >
{{story}}
per Story
</mat-radio-button >
<br><br>
<mat-radio-button formControlName="select1" value=oth ngDefaultControl >
{{oth}}
both
</mat-radio-button>
</mat-radio-group>
here is my ts file
onSearchChange(searchValue): void {
alert(searchValue);
this.Totalprice = parseFloat((parseFloat(this.price) * parseFloat(searchValue)).toFixed(2));
this.TotalGst = parseFloat((((this.Totalprice) * 2) / 100).toFixed(2));
this.finalamt = (this.Totalprice) + (this.TotalGst);
}
I want a checked radio button value in onSearchChange method,please help me with this
Solution
You have to call onSearchChange
in a (change)
event on your radio buttons like this:
<mat-radio-group formControlName="select1" >
<mat-radio-button formControlName="select1" value=post1 ngDefaultControl (change)="onSearchChange($event.target.value)">
{{post1}}
per post
</mat-radio-button>
<br><br>
<mat-radio-button formControlName="select1" value=story ngDefaultControl (change)="onSearchChange($event.target.value)">
{{story}}
per Story
</mat-radio-button>
<br><br>
<mat-radio-button formControlName="select1" value=oth ngDefaultControl (change)="onSearchChange($event.target.value)">
{{oth}}
both
</mat-radio-button>
</mat-radio-group>
you can also pass the radio value as parameter in onSearchChange
instead of $event.target.value
Answered By - Salvatore Maruccio
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.