angularjs – 如何清除从AngularUI typeahead输入的文本

前端之家收集整理的这篇文章主要介绍了angularjs – 如何清除从AngularUI typeahead输入的文本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个预先输入。输入文本设置为在字母开头选择的选项。但是,我想清除这个文本,并在我从typeahead中选择一个选项后再次在文本框中显示“占位符”值(因为我在selectMatch()方法中将选定的值添加到另一个div。
<input id="searchTextBoxId" type="text" 
    ng-model="asyncSelected" placeholder="Search  addresses..."
    typeahead="address for address in getLocation($viewValue) | filter:$viewValue"
    typeahead-loading="loadingLocations" class="form-control"
    typeahead-on-select="selectMatch(asyncSelected)" typeahead-min-length="3"
    typeahead-wait-ms="500">

我试图使用它的Id设置Input元素的文本值和占位符值,但是没有工作,例如这些:

// the input text was still the 
$('#searchTextBoxId').attr('placeholder','HELLO');

选择结果

// the input text was still the selected result
$('#searchTextBoxId').val('');

如何设置或重置文本值?

我正在寻找一个答案,以及,最长的时间。我终于找到了一个对我有用的决议。

我最终设置NgModel为typeahead-on-select属性中的一个空字符串:

在您的typeahead-on-select属性中,添加asyncSelected =”;在你的select函数后面,像这样:

<input ...
    typeahead-on-select="selectMatch(asyncSelected); asyncSelected = '';" />

让你的最后一个字母看起来像:

<input id="searchTextBoxId" type="text" 
    ng-model="asyncSelected" placeholder="Search  addresses..."
    typeahead="address for address in getLocation($viewValue) | filter:$viewValue"
    typeahead-loading="loadingLocations" class="form-control"
    typeahead-on-select="selectMatch(asyncSelected); asyncSelected = '';" 
    typeahead-min-length="3"
    typeahead-wait-ms="500">

Fiddle assigning the value to a variable

Fiddle adding each selection to an array

猜你在找的Angularjs相关文章