user1552545 user1552545 - 1 year ago 276
AngularJS Question

Bootstrap $uibModal focus to element

I've created an AngularJs directive, which sets focus to a html element.
But it doesn't work on $uibModal elements:

.directive('focus', ['$timeout', function ($timeout) {
return {
restrict: 'A',
link: function postLink(scope, element, attrs) {
scope.$watch(attrs.focus, function(value) {
if(value === true) {
$timeout(function() {

How can I set focus to an element inside a $uibModal?

Answer Source

I've found the solution: When I add the autofocus attribute to an input element, the $uibModal sets the focus to it.

    <div class="modal-body">
        <p class="input-group">
          <input type="text" class="form-control" autofocus/>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download