Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 error "Unhandled Promise rejection: Template parse errors:"

When I use the ngClass directive like this:

[ngClass]="{has-error: !myInput.valid}"

I get the following error:

Unhandled Promise rejection: Template parse errors: Parser Error: Missing expected : at column 5 in [{has-error: !myInput.valid}] in ...html...

How can I solve this error?

like image 511
Eran Shabi Avatar asked May 18 '26 03:05

Eran Shabi


1 Answers

The problem is with the -(dash) character in the has-error class name.

If your class name got a dash in its name, you must use quotes like this:

[ngClass]="{'has-error': !myInput.valid}"
like image 78
Eran Shabi Avatar answered May 20 '26 17:05

Eran Shabi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!