2

我想建立一個指令,使角度UI $ uibModal可拖動。當模式拖動時,我也想關閉所有打開的模式體中的ui-select下拉列表。以編程方式關閉所有ui-select下拉列表?

有沒有人知道如何關閉所有ui-select列表中的$uibModal

jsbin https://jsbin.com/lopitopiwa/edit?html,js,output

angular.module('myApp').directive('uibModalDragging',[ 
    UibModalDragging 
]); 


function UibModalDragging() { 
    return { 
     restrict: 'A', 
     scope: false, 

     link: function (scope, iElem, iAttrs) { 
      $(iElem).closest('.modal-content').draggable({ 
       handler: '.panel-heading', 
       start: onStart 
      }) 
     } 
    }; 

    function onStart() { 
     //********************************************* 
     //close all ui-select ??? 
    } 
} 

回答

1

這是更好的辦法,但你需要根據這個創建另一個指令:

https://github.com/angular-ui/ui-select/wiki/Accessing- $選擇

angular.module('myApp').directive('myUiSelect', function() { 
    return { 
    require: 'uiSelect', 
    link: function(scope, element, attrs, $select) { 
     scope.$on('closeAll', (ev,val)=>{ 
     $select.close(); 
     }); 
    } 
    }; 
}); 

,然後將其添加到您的元素:

<ui-select my-ui-select ng-model="selected.value"> 
        <ui-select-match> 
         <span ng-bind="$select.selected.name"></span> 
        </ui-select-match> 
        <ui-select-choices repeat="item in myModalCtrl.itemArray"> 
         <span ng-bind="item.name"></span> 
        </ui-select-choices> 
       </ui-select> 

,只是廣播事件後關閉這裏的一切例如:

https://jsbin.com/cadekafata/1/edit?html,js,console,output