我目前正在使用一个 typeahead 输入指令组件,它工作正常但缺乏某些功能。该组件通过查询获取所有需要的数据,该查询在页面加载后立即触发并选择预定义的默认条目。然而,总是至少有 15 个可用条目,但为了在同一个下拉列表中创建新记录,我想在搜索列表的末尾添加一个“创建按钮”。因此,如果用户键入任何字符串并且它在下拉列表中不可用,那么他/她可以通过该按钮创建记录。有没有办法创建打字稿的自定义版本,我可以在其中添加一个按钮来保存在文本框中输入的记录?
<h4>Custom popup templates for typeahead's dropdown</h4>
<pre>Model: {{customPopupSelected | json}}</pre>
<input type="text" ng-model="customPopupSelected" placeholder="Custom popup template" uib-typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue}" typeahead-popup-template-url="customPopupTemplate.html" class="form-control">
<script type="text/ng-template" id="customPopupTemplate.html">
<div class="custom-popup-wrapper"
ng-style="{top: position().top+'px', left: position().left+'px'}"
style="display: block;"
ng-show="isOpen() && !moveInProgress"
aria-hidden="{{!isOpen()}}">
<p class="message">select location from drop down.</p>
<ul class="dropdown-menu" role="listbox">
<li class="uib-typeahead-match" ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }"
ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)" role="option" id="{{::match.id}}">
<div uib-typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></div>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)