Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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 – 如何清除从AngularUI typeahead输入的文本全部内容,希望文章能够帮你解决angularjs – 如何清除从AngularUI typeahead输入的文本所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。