Reputation: 12179
Can I get the ElementRef
from doWidth()
?
<div [style.left.px]="doWidth(maybeThisElementRef)">
</div>
Rather than turning the div into a component?
Upvotes: 0
Views: 1053
Reputation: 28708
In addition to yurzui's answer, you can also reference it in your components as this:
<div #el [style.left.px]="doWidth()">
import { ViewChild } from '@angular/core';
....
@ViewChild('el') private el;
...
doWidth(){
this.el.value="blabla" //or something else
}
Upvotes: 1
Reputation: 214095
Just use template reference variable like:
<div #el [style.left.px]="doWidth(el)">
See also
Upvotes: 2