0

Fairly simple but I can't figure out the term I need to google. How do I reference whichever element is calling the controllers blurr function?

html

<body ng-app="test">
  <div ng-controller="Cntrlr as cntrlr">
    <input type="text" ng-model="cntrlr.inpt" ng-blur="cntrlr.blurr()" />
    <input type="text" ng-model="cntrlr.second" ng-blur="cntrlr.blurr()" />
  </div>
</body>

js

var app = angular.module("test", []);
app.controller("Cntrlr", ["$scope", function($scope){
  this.blurr = function(){
    alert("which input am I?");
    alert("this is so meta.");
    // ?
  };
}]);

[edit]

I realized I meant to be more abstract than I was so I created a new question because this one has been solved

Community
  • 1
  • 1
Andrew Luhring
  • 1,762
  • 1
  • 16
  • 37

1 Answers1

2

You could pass the $event to the function, and figure out the target of the event from that:

<input type="text" ng-model="cntrlr.inpt" ng-blur="cntrlr.blurr($event)" />
<input type="text" ng-model="cntrlr.second" ng-blur="cntrlr.blurr($event)" />

And

$scope.blurr = function(event){
    var $this = $(event.target);
    console.log($this);
};
dave
  • 62,300
  • 5
  • 72
  • 93