代码之家  ›  专栏  ›  技术社区  ›  user4143172

以编程方式关闭所有ui选择下拉列表?

  •  2
  • user4143172  · 技术社区  · 7 年前

    有人知道如何关闭所有 ui-select a中的列表 $uibModal ?

    杰斯宾 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 回复  |  直到 7 年前
        1
  •  1
  •   pegla    7 年前

    这是更好的方法,但您需要根据以下内容创建另一个指令:

    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