Best practice for referencing this.element

Hi,

Just a quick question as I dont find it explicitly in the documentation.What’s the current best practice for referencing the component’s DOM element from the controller?

Is it to inject the INode list this?

import {inject, INode} from "aurelia";

@inject(INode)
export class MyComponent {
    constructor(private element: INode) {}
}

That seems to be working, but I’m not sure if it’s idiomatic Aurelia.

Thanks for any input.

I don’t know the best practice, but you can also just inject @inject(Element)

constructor(protected element: Element) {
2 Likes

Sorry, this post flew under the radar for me when I took a couple of weeks break. So, yeah, injecting element or INode will get you the element instance itself for the component or attribute. For anything else you would want refattribute.