Q: Focus textarea on iOS with angularjs I currently trying to set focus on a textarea on ipad which isn't touched by the user.
The reason for this is that I want to another action on a single tap than on a double tap.
I tried to make a plnkr work but I couldn't. For some reasons plnkr don't want to use my eventhandling. Thatswhy I only could show you my code.
Plunker
This part works very well on Andriod, Windows Mobile, MacOS and PC but not on iOs:
angular.module('App').direktive('setFocusOnInput', ['$timeout', function($timeout) {
        return {
            scope: {
                trigger: '@setFocusOnInput',
                elementId: '@'
            },
            link: function($scope, $elm, $attr, $ctrl) {
                $scope.$watch('trigger', function(value) {
                    if(value === $scope.elementId) {
                        $timeout(function() {
                            $elm.focus();
                        });
                    } else {
                        angular.element(document.activeElement).blur();
                    }
                });
                $elm.on('blur', function() {
                    $scope.trigger = null;
                });
            }
        }
    }]);


A: I found a solution which worked for me:
    .directive('setFocusOnInput', ['$timeout', function($timeout) {
        return {
            scope: {
                trigger: '@setFocusOnInput',
                elementId: '@'
            },
            link: function($scope, $elm, $attr, $ctrl) {
                $scope.$watch('trigger', function(value) {
                    if(value === $scope.elementId) {
                        if(window.navigator.userAgent.indexOf('iPad') > -1 || window.navigator.userAgent.indexOf('iPod') > -1) {
                            $elm.focus();
                            $timeout(function() {
                                document.activeElement.focus();
                            },750);
                        } else {
                            $timeout(function() {
                                $elm.focus();
                            });
                        }
                    } else {
                        angular.element(document.activeElement).blur();
                    }
                });
                $elm.on('blur', function() {
                    $scope.trigger = null;
                });
            }
        }
    }])

iOS doesn't accept the timeout to set the Dom-element as activeElement. But if it is set, you have to set another focus on the activeElement. It's a cheese solution but maybe somebody will have a simular problem and could use this solution.
