NOTE: Not a duplicate of above. Above is accessing clicked element, this question is about accessing a different element.
QUESTION
How can I pass an element (not the clicked element) from my html document to an Angular scope method in an ng-click?
Example: http://jsfiddle.net/Ld8Zs/2/
HTML:
<body ng-app="myApp">
<div ng-controller="myController">
<input type='text'></input>
<button ng-click="clickHandler($('input'));">One</button>
<button onclick="alert(typeof $('input'));">Two</button>
</div>
</body>
JavaScript:
var app = angular.module('myApp', []);
app.controller('myController', function($scope) {
$scope.clickHandler = function(el) {
alert(typeof el);
// real code work with element---set focus
}
});
In this example when you click the second button, which uses onclick you get "object". When you click on the first button which passes through ng-click you get "undefined".
I'm trying to avoid moving the jQuery code itself into the controller or into Angular in general to maintain testability.
EDIT:
My original example used jQuery to find the first <button> element which is easily handled by $event. This is not actually indicative of the problem I want to solve and was my mistake in translating my actual problem to a simple reproducible.
The linked duplicates are not the same problem.