user1552545 user1552545 - 4 months ago 94
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?


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/>