2016-02-01 46 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對於在使用過濾器時沒有結果時「允許我調用事件(打開模式)」的解決方案的請求,除非需要用戶點擊一個按鈕是可以接受的。但我的印象是,意圖是要立即觸發該事件。 –