I have a button on my screen where if the user has already added clicked on it, it is a mat-filled-button but if I haven't clicked on it, it is a mat-button
My code looks like this
<button
*ngIf="myVote !== 'UPVOTE'"
mat-button
color="primary"
(click)="onVote('UPVOTE')"
>
UPVOTE
</button>
<button
*ngIf="myVote === 'UPVOTE'"
mat-flat-button
color="primary"
(click)="onVote('NONE')"
>
UPVOTE
</button>
Basically I have two buttons and only one shows. Obviously, this is very ugly.
Is there a way where I can achieve the same outcome with only one button and it conditionally is a mat-flat-button
or a mat-button
based on a set of logic?
Try like this:
<button
mat-button
[class.mat-flat-button]="myVote === 'UPVOTE'"
color="primary"
(click)="onVote(myVote === 'UPVOTE'? 'NONE' :'UPVOTE')"
>
UPVOTE
</button>
See Working Demo
_ I have used raised button the demo for better visibility.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With