Focus second element in modal window (Angular, Bootstrap UI)

354 Views Asked by At

I have two buttons in modal window. When I open window, the first button is focused. How can I change a focus to second button?

1

There are 1 best solutions below

3
On

When using multiple directive it is best to use attr observe as u can run into issue of multiple directive creating isolate scope

app.directive('focusMe', function ($timeout) {
    return {
        link: function (scope, element, attr) {
            attr.$observe('focusMe', function (value) {
                if (value === "true") {
                    $timeout(function () {
                        element[0].focus();
                    });
                }
                else
                {
                    $timeout(function () {
                        element[0].focusout();
                    });
                 }
            });
        }
    };
});

<input name="button1" focus-me="false" type="text"/>
<input name="button2" focus-me="true" type="text"/>