2016-02-01 48 views
0

我正在使用https://github.com/angular-ui/ui-select,我想要做一些事件或一个选项,当我使用过滤器时没有找到结果时,我可以调用一个事件(打开模式)。ui-select no result event

<ui-select ng-model="SelectedCustomer.selected" theme="select2"> 
<ui-select-match placeholder="Enter Customer"> 
    {{$select.selected.NAME}} 
</ui-select-match> 
<ui-select-choices repeat="customer in Customers | filter: $select.search"> 
    <div ng-bind-html="customer.NAME | highlight: $select.search"></div>    
</ui-select-choices> 

+0

http://stackoverflow.com/questions/14615495/angularjs-placeholder-for-empty-result-from-filter –

回答

0

只需添加下面的界面,选择一个div使用NG-如果您的选择。像这样:

<ui-select-choices 
    ng-repeat="customer in filterSearch = (Customers | $select.search)"> 
    <div ng-bind-html="customer.NAME | highlight: $select.search"></div>    
</ui-select-choices> 
<div ng-if="!filterSearch"><button ng-click="openDialog()"></button></div> 

什么是您的示例中的$ search?

+0

$搜索,在输入文本我与搜索由ui-select插件提供。 这是有效的如果我正在做我自己的自定义过滤器,ui-select正在为我做。 –

0

您可以在UI的选择,像下面后添加<ui-select-no-choice>指令的用户界面,选择指令内:

<ui-select multiple ng-model="something" > 
    <ui-select-match placeholder="something" allow-clear="true"> 
    </ui-select-match> 
    <ui-select-choices> 
    </ui-select-choices> 
    <ui-select-no-choice> 
     This is where your code goes in. You can display some message or you can create a button too. 
    </ui-select-no-choice> 
</ui-select> 

这会像你的愿望。 参考,使用情况,您可以看到ui-select-no-choice documentation

+0

这是一个很有用的指示,但它不符合OP对于在使用过滤器时没有结果时“允许我调用事件(打开模式)”的解决方案的请求,除非需要用户点击一个按钮是可以接受的。但我的印象是,意图是要立即触发该事件。 –