Last active
December 20, 2015 06:59
-
-
Save alanmoo/6089544 to your computer and use it in GitHub Desktop.
When repeating radio inputs, use this AngularJS directive to make the browser focus on the active input.
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
angular.module('myApp', []) | |
.directive('focusActive', function(){ | |
return { | |
restrict: "A", | |
link: function(scope, element, attrs) { | |
attrs.$observe('checked', function(){ | |
if (element[0].checked){ | |
element.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
<!-- Use by calling focus-active as input attribute--> | |
<div ng-repeat="status in statuses"> | |
{{status}}<input focus-active type="radio" ng-model="person.location" value="{{status}}"> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment