Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass in element to function in Angular

Tags:

angular

I would like to conditionally apply a title attribute to an element, which I am attempting like so:

<div class="option-title" [attr.title]="isTitleTruncated() ? option.title : null">
  {{option.title}}
</div>

But I would like to pass in the element reference to my function being used on the condition, but have been unable to do so. I tried using this and that gives me the component instance, but I want the actual div itself. Is this possible?

like image 309
mindparse Avatar asked May 30 '26 02:05

mindparse


1 Answers

Try using template reference variable like:

<div ... #divRef [attr.title]="isTitleTruncated(divRef) ? option.title : null">
like image 140
yurzui Avatar answered Jun 01 '26 20:06

yurzui



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!