我在输入字段中有一个typeahead属性,如下所示:
typeahead="user.email as user.lastname for user in uc.userList | filter:$viewValue | limitTo:8"
所以,我使用姓氏作为预先输入功能的标签来绑定电子邮件地址。是否有可能将两个变量组合成一个标签,如下所示:
typeahead="user.email as (user.firstname AND user.lastname) for user in uc.userList | filter:$viewValue | limitTo:8"
答案 0 :(得分:1)
这个问题的最简单的解决方案是通过简单的字符串运算符来实际连接这两个值,如:
typeahead="user.email as user.firstname + ' ' + user.lastname for user in uc.userList | filter:$viewValue | limitTo:8"
此外,可以使用模板技术,例如typeahead-template-url,这里有更详细的解释:Bootstrap-UI Typeahead display more than one property in results list?
答案 1 :(得分:0)
您也可以使用typeahead-template-url
来实现此目的:
<div ng-controller="TypeaheadCtrl">
<input type="text" ng-model="customSelected"
typeahead="user.email for user in userList | filter:$viewValue | limitTo:8"
typeahead-template-url="customTemplate.html">
</div>
您已在模板文件中添加所需的列:
<script type="text/ng-template" id="customTemplate.html">
<a>
<span bind-html-unsafe="match.model.firstName | typeaheadHighlight:query"></span>
<span bind-html-unsafe="match.model.lastName | typeaheadHighlight:query"></span>
</a>
</script>