Setting focus on an input field after ng-show

后端 未结 5 787
遥遥无期
遥遥无期 2020-12-13 13:41

Is it possible set the focus of an input field via a controller once data has loaded (via $resource in this case)?

The input is hidden via ng-show until the data is

5条回答
  •  春和景丽
    2020-12-13 14:15

    This is a simple directive that might work for you

    
    
    .directive('focusOn',function($timeout) {
        return {
            restrict : 'A',
            link : function($scope,$element,$attr) {
                $scope.$watch($attr.focusOn,function(_focusVal) {
                    $timeout(function() {
                        _focusVal ? $element[0].focus() :
                            $element[0].blur();
                    });
                });
            }
        }
    })
    

提交回复
热议问题