这是更好的方法,但您需要根据以下内容创建另一个指令:
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