2014-02-25 205 views
4

當我點擊一個按鈕時,如果你點擊彈出窗口中的按鈕,彈出窗口就會關閉。但是,如果您單擊另一個按鈕打開彈出窗口,則會同時看到兩個彈出窗口,而我只想保留一個彈出窗口。關閉AngularStrap彈出窗口

我嘗試過使用觸發器「focus」,但是如果單擊popover內的textarea,它會關閉彈出窗口,我希望當您單擊彈出窗口之外時調用此觸發器。

對此有何想法?可以從控制器調用$ hide,$ show方法嗎?

+0

我太迫切需要這個問題的答案...有沒有人有任何想法? – rmehlinger

+0

將屬性auto-close ='1'添加到按鈕或標籤。 –

回答

1

好吧,我很確定這是一個可怕的黑客攻擊,但這裏就是這樣。假設你的popover模板都使用popover類(如果你沒有使用帶有data-template屬性的自定義模板,它們應該),並且它們是觸發它們的按鈕的兄弟(如果你沒有使用容器屬性,它們是),您可以將以下指令應用於彈出式按鈕。注意:這假設彈出和彈出式按鈕的父元素具有唯一的ID。

angular.module('yourApp.directives', []).directive('rmPopovers', 
    function($document,$rootScope,$timeout,$popover) { 
     return { 
      restrict: 'EA', 
      link : function(scope, element, attrs) { 
       var $element = $(element); 
       $element.click(function() { 
        $('.popover').each(function(){ 
         var $this = $(this); 
         if($this.parent().attr('id') != $element.parent().attr('id')) 
         { 
          $this.scope().$hide(); 
         } 
        } 
        ); 
       }); 
      } 
     } 
    } 
); 

然後

<button type="button" bs-popover rm-popovers [your data attribs here]>Button!</button 
+0

多麼美妙的解決方案!非常感謝你 – grouser

4

嘗試在popover的可排除元素上添加ng-click="$hide()"。即:

<a class="btn btn-primary" ng-click="$hide()">Close</a> 

它不包含在文檔中,但它爲我工作,當且僅當您使用酥料餅的內容數據的模板,也沒有與其他開酥料餅試過沒。

2

這應該是個老問題了,在角帶的最新版本,新的屬性可以在這種情況下使用: auto-close='1'

-1
trigger : 'focus' , 

爲我工作就同一問題