javascript – 如何在角度预先搜索中使用ng-change
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 如何在角度预先搜索中使用ng-change,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1901字,纯文字阅读大概需要3分钟。
内容图文
![javascript – 如何在角度预先搜索中使用ng-change](/upload/InfoBanner/zyjiaocheng/736/ee6be518d0f0481b97dd1960d7d230a4.jpg)
我想在按键事件上搜索用户列表.我使用customTemplate.js显示列表,但是在第一个按键结果列表中没有显示.
这是我的代码:
<input type="text" placeholder="Search people here..." ng-change="getMatchedUser();" ng-model="selected" data-typeahead="user as user.name for user in searchMembers | filter:$viewValue" typeahead-on-select="onSelect($item, $model, $label)" typeahead-template-url="customTemplate.html" />
<script type="text/ng-template" id="customTemplate.html">
<a style="cursor: pointer;">
<div class="search-div">
<span style="float: left;"><img ng-src="<?php echo base_url().UPLOAD_PROFILE ?>{{match.model.imageUrl}}" width="30" class="img-circle"></span>
<div class="search-name">
<span>{{match.model.name}}</span><br/>
<span ng-if="match.model.skillName.length">
<i class="skill">{{match.model.skillName}}</i>
</span>
</div>
</div>
<div style="padding-bottom:42px;" ng-if="match.model.length == 5">
<a href="<?php echo base_url(); ?>#/searchResult" style="float: left; padding: 18px 1px 5px 8px; color: black;">
Show More Results
</a>
</div>
</a>
</script>
$scope.getMatchedUser = function(){
$scope.searchValue = $scope.selected;
$http({
method : "POST",
url : BASE_URL + 'getMatchedUser',
data : $.param({"typeValue": $scope.selected}),
headers : { 'Content-Type' : 'application/x-www-form-urlencoded'}
}).success(function(data){
if(data.status == "success"){
$scope.searchMembers = data.searchMembers;
}
});
};
解决方法:
在更新ng模型之前实际触发了ng-change.
我发现的一个解决方案就是将typeahead-wait-ms属性(对于可忽略的时间范围)添加到您的先行输入元素
<input type="text"
placeholder="Search people here..."
ng-change="getMatchedUser();"
ng-model="selected"
data-typeahead="user as user.name for user in searchMembers | filter:$viewValue"
typeahead-wait-ms=10
typeahead-on-select="onSelect($item, $model, $label)"
typeahead-template-url="customTemplate.html" />
这个10ms的暂停应该足以允许在触发ng-change事件之前更新ng-model.
内容总结
以上是互联网集市为您收集整理的javascript – 如何在角度预先搜索中使用ng-change全部内容,希望文章能够帮你解决javascript – 如何在角度预先搜索中使用ng-change所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。