Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngClass if string length

Tags:

angular

I want to add a class to my div if a string is larger than 10 characters, I try this but didn't work

<div class="page-heading" ngClass="{'hidden-lines':post.title.length > 10}">
like image 401
efirvida Avatar asked Feb 11 '26 13:02

efirvida


1 Answers

You need to box it using [] so that becomes [ngClass]. This notation is used for expression binding.

<div class="page-heading" [ngClass]="{'hidden-lines':post.title.length > 10}">
like image 70
Igor Avatar answered Feb 14 '26 02:02

Igor



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!