Idov
Idov

Reputation: 5134

AngularJS 1.6 -Accessing elements in the component's template

How can I access an element in my component template from my js code?
Suppose I have many components with this template:

<div style="width: inherit; height: inherit;">
    <img class="elem"> </img>
</div>

and I want each component's controller to access its own img - how can I do it?

Upvotes: 3

Views: 432

Answers (1)

Bartek Fryzowicz
Bartek Fryzowicz

Reputation: 6684

You can inject $element into your component controller:

componetnController($element) {
    let img = $element.find('img');
}

Upvotes: 1

Related Questions