Created
November 15, 2012 00:52
-
-
Save revolunet/4075928 to your computer and use it in GitHub Desktop.
Angular focusMe directive, watch example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// copied from http://plnkr.co/edit/1LhUJ4?p=preview | |
angular.module('myApp', []) | |
.directive('focusMe', function () { | |
return { | |
restrict: 'A', | |
scope: { | |
focusMe: '=' | |
}, | |
link: function (scope, elt) { | |
scope.$watch('focusMe', function (val) { | |
if (val) { | |
elt[0].focus(); | |
} | |
}); | |
} | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="utf-8"> | |
<title>Custom Plunker</title> | |
</head> | |
<body ng-app="myApp"> | |
<input type="checkbox" ng-model="checked"> | |
<input focus-me="checked"> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script> | |
<script src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment