Small AngularJS v1 directive to trigger the focus event on HTML elements after some $scope or $rootScope event.
- AngularJS v1.x
Bower
bower install angular-focus-on --save
NPM
npm install angular-focus-on --save
...or download it.
<script src="assets/vendor/angular-focus-on.min.js"></script>
angular.module("yourApp", ["angularFocusOn"]);
<input type="text" name="inputText" angular-focus-on="someScopeEvent">
<textarea name="textareaBox" angular-focus-on="someScopeEvent"></textarea>
select-after-focus
Limited to <input type="text">
fields and <textarea>
boxes.
When the field is focused, select its contents
Usage:
<input type="text" angular-focus-on="someScopeEvent" select-after-focus="">
no-timeout
By default, the directive will wait the event loop to focus on the element, you can disable that by adding the no-timeout
attribute.
Usage:
<input type="text" angular-focus-on="someScopeEvent" no-timeout="">
This is a simple directive I've been using for a while, if you think this solution can be improved, feel free to fork the repo and make your changes.