Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't bind to 'ngClass' since it isn't a known property of 'button' [duplicate]

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.

like image 345
BentOnCoding Avatar asked Dec 01 '16 04:12

BentOnCoding


1 Answers

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

like image 119
Chris Noffke Avatar answered Oct 18 '22 23:10

Chris Noffke