[英]Angucomplete-alt using ng-scope on the autocomplete tag
I have a form with an input tag where I want to use auto-complete, user is allowed to enter a name and auto-complete suggestions appear as user enters name characters. 我有一个带有输入标签的表单,我想在其中使用自动完成功能,允许用户输入名称,并且当用户输入名称字符时会出现自动完成建议。
My problem is what if user doesn't want to use the auto-complete names and wish to use a custom name how do I get access to this in my controller. 我的问题是,如果用户不想使用自动完成名称并希望使用自定义名称,该如何在控制器中访问此名称。
I am not able to set ng-model on this input tag as it is managed internally by the angucomlete-alt . 我无法在此输入标签上设置ng-model,因为它是由angucomlete-alt内部管理的。
I have this autocomlete-alt tag in ng-repeat. 我在ng-repeat中有这个autocomlete-alt标记。
<div ng-repeat="resident in vm.residents">
<div class="form-group">
<label class="col-lg-2 col-sm-2 control-label">Name</label>
<div class="col-lg-6">
<angucomplete-alt
placeholder="Name"
pause="100"
selected-object="residentSelected"
search-fields="name"
title-field="name"
minlength="1"
remote-api-handler="searchApi"
remote-url-response-formatter="searchResponseFormatter"
input-class="form-control form-control-small"
match-class="highlight"
clear-selected="true">
</div>
</div>
</div>
Further my requirement is to set fields of the selected object on other input tags which are below name field how can I set the fields on resident(iterator)
via model binding. 另外,我的要求是将所选对象的字段设置在名称字段下方的其他输入标签上,如何通过模型绑定在resident(iterator)
上设置字段。
I am not able to set ng-model on augucomplete-alt so that it reflects on resident(iterator)
of ng-repeat. 我无法在augucomplete-alt上设置ng-model,以使其反映在ng-repeat的resident(iterator)
上。
My aim is to be able to assign/bind values to resident
from the angucomplete tag itself. 我的目标是能够从angucomplete标签本身为resident
分配/绑定值。
Can anyone help me thanks in advance. 任何人都可以提前帮助我。
Well you simply need to do is this .... 好吧,您只需要做的就是这个....
<angucomplete-alt
placeholder="Name"
pause="100"
selected-object="residentSelected"
search-fields="name"
title-field="name"
minlength="1"
remote-api-handler="searchApi"
remote-url-response-formatter="searchResponseFormatter"
input-class="form-control form-control-small"
match-class="highlight"
clear-selected="true"
override-suggestions="true"/>
override-suggestions="true" : this attribute overrides your selection and set your selected-object attribute to the custom input you type in the field. overlay-suggestions =“ true”:此属性将覆盖您的选择,并将您选择的对象属性设置为您在字段中键入的自定义输入。
Use override-suggestions. 使用替代建议。 Take a look at this example 4 看一下这个例子4
http://ghiden.github.io/angucomplete-alt/#example4 http://ghiden.github.io/angucomplete-alt/#example4
Here is a working example with ng-repeat 这是ng-repeat的工作示例
http://plnkr.co/edit/6IiUul?p=preview http://plnkr.co/edit/6IiUul?p=preview
$scope.residentSelected = function(selected) {
if (selected.originalObject.name) {
$scope.vm.residents[this.$parent.$index].name = selected.originalObject.name;
} else {
console.log('overriding selection');
$scope.vm.residents[this.$parent.$index].name = selected.originalObject;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.