Kyle Boucher
Kyle Boucher

Reputation: 108

Get element that has focus from ngFocus

Is there a way to get the innerHTML of the element that triggers a ngFocus or ngBlur?

<textarea ng-focus="focus()"></textarea>

then in my controller I have

$scope.focus = function() {
    //I need innerHTML here of the textarea that triggered me
}

Upvotes: 0

Views: 819

Answers (2)

ARIF MAHMUD RANA
ARIF MAHMUD RANA

Reputation: 5166

focus(this)

will not pass DOM element to the function focus(this). Here this will refer to the scope. If you want to access the DOM element use focus($event). In the callback function you can get the DOM element by event.target

Source copied from http://stackoverflow.com/a/13000154

Upvotes: 1

Pankaj Parkar
Pankaj Parkar

Reputation: 136144

You could use ng-model on that text area. So while ng-focus event gets fired you could get that value from scope of the controller easily.

Upvotes: 0

Related Questions