Angular: simple focus directive
http://angularjs.org/
by johnwun
HTML
<script src="http://code.angularjs.org/angular-1.0.0rc12.js"></script>
<div ng-controller="MyCtrl">
<input><button ng-focus="onFocus()">Login</button>
</div>
JavaScript
var myApp = angular.module('myApp', []);
myApp.directive('ngFocus', function() {
return function(scope, element, attrs) {
element.bind('focus', function(){
scope.$eval(attrs.ngFocus)
});
}
});
function MyCtrl($scope) {
$scope.onFocus = function(){
console.log("I'm focused!");
}
}