ali ali - 23 days ago 7
AngularJS Question

Directive does not work in bootstrap modal dialog

I wrote a basic angular directive to get focus on elements. It works fine in different pages, but it does not work in modal dialog which I created with Bootstrap components.

my directive is :

myApp.directive('focus', function () {
return {
restrict: "A",
link: function (scope, element, attrs) {
console.log('directive ' + element);
angular.element(element).focus();

}
};


});

thanks for any help

Answer
myApp.directive('focus', function () {
return {
    restrict: "A",
    link: function (scope, element, attrs) {
        console.log('directive ' + element);
        setTimeout(function(){angular.element(element).focus();}, 200);

    }
};

when you try to set the focus, the element is not yet visible