弹出窗口时,关闭弹出窗口中的关闭按钮

时间:2015-08-26 14:45:53

标签: javascript jquery angularjs

我的 div

     <div id="modal"   tabindex="-1" ng-show="booleanvariable" ></div>
ng-show 为真时,我显示,但是我在div下面有关闭按钮,当div需要聚焦时显示。我们可以使用

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

是否有像 onShow 这样的节目事件,因此我将把上面的代码放在onShow事件中。

谢谢, 巴拉吉。

1 个答案:

答案 0 :(得分:2)

您可以观看绑定到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();
            });
        }
    }
});