HTML:
<button class="sa-button" [ngClass]="'buttonClass'">{{displayText}}</button>
The variable I expect to bind to in my typescript file:
public buttonClass = "button";
The error I get:
Can't bind to 'ngClass' since it isn't a known property of 'button'
I want to bind a variable which holds the name of the css class I want to apply.
Is there a correct way to do this? I literally copied this out of the angular docs, and it doesn't work.
by adding the single quotes, you are passing in the text in the single quotes.
You want to remove them like so...
<button class="sa-button" [ngClass]="buttonClass" >{{displayText}}</button>
Fro more on ngClass, check out the docs
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