angularjs Angular-UI Typeahead,如何禁用几行,不允许对这些字段进行选择

ukqbszuj  于 8个月前  发布在  Angular
关注(0)|答案(1)|浏览(84)

在Angular UI构建的普通Typeahead中,

<input type="text" ng-model="asyncSelected" placeholder="Locations loaded via $http" typeahead="address for address in getLocation($viewValue)" typeahead-loading="loadingLocations" class="form-control">

如何禁用某些行并不允许选择这些字段。
比如类似于Select2禁用选项。

vhmi4jdf

vhmi4jdf1#

我知道,这是一个古老的问题,但似乎仍然没有答案。我所做的是创建一个自定义的PopupTemplate,即使之前有不同的原因。在这个PopupTemplate中,你可以在li-元素上使用ng-class:对于自定义模板:

typeahead-popup-template-url="templates/typeaheadPopupTemplate.html"

在模板文件中(不过,您必须搜索正确的作用域):

<li class="uib-typeahead-match" ng-repeat="match in matches" ng-class="{active: $parent.$parent.$parent.funcItmIsActive($index, $parent), disabled: $parent.$parent.$parent.funcItmDisabled(match) }" >
<div uib-typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></div>
</li>

然后在控制器中:

$scope.funcItmDisabled = function (itm) {
                    let result = false;
//loading is to check, if the Control is loading atm. because the list is sometimes loaded from Service.
                    if (!$scope.loading && itm && itm.model && itm.model.itm) {
                        if ($scope.SelectionDisabledIf) {
                            result = itm.model.itm.DisabledFlag === true;
                        }

                    }
                    return result;
                };

相关问题