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