简体   繁体   English

如果找不到项目,Angular ng-select autocomplete 如何提供“创建新项目”的选项?

[英]Angular ng-select autocomplete how to provide option to "create new item" if No Items found?

In ng-select (Angular), is there a way to provide "Create New" if no matches in the data list based on user search?在 ng-select (Angular) 中,如果基于用户搜索的数据列表中没有匹配项,是否有办法提供“新建”?

I like to create new items like the reference image below when no matches are found.当找不到匹配项时,我喜欢创建新项目,例如下面的参考图片。

在此处输入图像描述

As per ng select config, we have the option to set only text for not Found Text (notFoundText).根据 ng select config,我们可以选择只为未找到的文本 (notFoundText) 设置文本。 I didn't have any HTML Template option to provide.我没有提供任何 HTML 模板选项。

Any suggestions?有什么建议么?

Ng-select Stackblitz - https://stackblitz.com/edit/ng-select-not-fount-text-not-working-5gcdlq?file=src%2Fbindings-default-example.component.ts,src%2Fbindings-default-example.component.html NG-选择 Stackblitz - https://stackblitz.com/edit/ng-select-not-fount-text-not-working-5gcdlq?file=src%2Fbindings-default-example.component.ts,src%2Fbindings-default -example.component.html

We can pass a template like below.我们可以传递如下模板。

<ng-select 
[items]="defaultBindingsList" 
[(ngModel)]="selectedCity"

>
<ng-template ng-notfound-tmp let-searchTerm="searchTerm">
<div class="ng-option disabled">
    No data found for "{{searchTerm}}". Do you want to create new?
    <button>Create New</button>
</div>
</ng-template>
</ng-select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM