弹出时弹出窗口中的焦点关闭按钮

focus close button in the popup when it is popped up

我有一个 div 作为

     <div id="modal"   tabindex="-1" ng-show="booleanvariable" ></div>

ng-show 为真时,我 show,但是我有 close 按钮在 div 下,当 div 为 showed.We 时需要重点关注,可以使用

      $timeout(function() 
         {
                $('.close').focus();
         }, 5000);

有没有像onShow这样的show事件,所以我会把上面的代码放在onShow事件中。

谢谢, 巴拉吉.

您可以看到您的模型绑定到 ng-show 并在达到正确状态时触发它。

$scope.$watch('isShown', function(newValue, oldValue) {
    if (newValue !== oldValue) {
        $log.log('Changed!');
        if(newValue === true) {
            angular.element('.close').focus();
            // or you might have to wrap it with $timeout
            $timeout(function(){
                angular.element('.close').focus();
            });
        }
    }
});