角度 ui 类型提前建议 + 如果没有结果,则保留

angular ui-typeahead Suggestions + Keep if no result

本文关键字:结果 如果没有 保留 类型 ui 角度      更新时间:2023-09-26

Controller

 $scope.log = function(value) {
        console.log(value);
    }
 $scope.customers = array....

视图

 <script type="text/ng-template" id="customPopupTemplate.html">
    <ul class="dropdown-menu" ng-show="isOpen() && !moveInProgress" ng-style="{top: position().top+'px', left: position().left+'px'}" style="display: block;" role="listbox" aria-hidden="{{!isOpen()}}">
        <li 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>
        <button type="button" class="btn btn-success"  ng-click="$parent.$parent.log(query);">Post</button>
       input: {{query}}
    </ul>
</script>
     <div class="form-group">
                                <input placeholder="Vælg kunde" type="text" ng-model="customer"  typeahead-editable="false" uib-typeahead="customer as customer.customer for customer in customers | filter:$viewValue | limitTo:8" class="form-control"
                                       typeahead-popup-template-url="customPopupTemplate.html"  >
                            </div>
当我输入输入

到预先输入时,没有结果下拉框消失了,我怎么能让我留下来

还想知道如何提前输入自动建议,当单击输入框时显示,它将显示下拉列表中的前 5

个下拉列表。

指令 uib-typeahead-popup 有一个隔离的范围。这意味着您不能在模板中使用任何作用域变量,除非在该指令的独立作用域中显式定义。使用此特定指令无法实现您想要的,除非您应用非常肮脏的技巧,例如向客户对象添加属性:

for (var i=0; i<customers.length; i++) {
    customers[i].whatadd = "something";
}

然后,您可以在模板中使用以下方法:

<a href="">+ add {{matches[0].whatadd}}....</a>

如果您不喜欢肮脏的技巧,那么您将不得不编写自己的 typeahead 指令,该指令没有隔离的作用域或允许您将添加指定为额外的属性。

相关文章: