相当简单,但我无法弄清楚我需要谷歌的术语。 如何引用调用控制器模糊函数的任何元素?
<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>
var app = angular.module("test", []);
app.controller("Cntrlr", ["$scope", function($scope){
this.blurr = function(){
alert("which input am I?");
alert("this is so meta.");
// ?
};
}]);
我意识到我的意思比我更抽象,所以我创建了new question,因为这个问题已经解决了
答案 0 :(得分:2)
您可以将$event
传递给该函数,并从中找出事件的目标:
<input type="text" ng-model="cntrlr.inpt" ng-blur="cntrlr.blurr($event)" />
<input type="text" ng-model="cntrlr.second" ng-blur="cntrlr.blurr($event)" />
和
$scope.blurr = function(event){
var $this = $(event.target);
console.log($this);
};