情况:
我有一个发送电子邮件的角度应用程序.
有三个字段:地址 – 主题 – 文本.
地址字段使用角度ui-select构建
电子邮件地址可以从列表中选择或重新输入.
问题是输入新的电子邮件地址.
我试图使用标记属性来获取它.
但据我所知,只有当ui-select由一组简单字符串组成而不是由一个对象数组组成时才能工作
码:
<h3>Array of objects</h3>
<ui-select multiple tagging tagging-label="new tag" ng-model="multipleDemo.selectedPeople" theme="select2" ng-disabled="disabled" style="width: 800px;">
<ui-select-match placeholder="Select person...">{{$item.name}} <{{$item.email}}></ui-select-match>
<ui-select-choices repeat="person in people | propsFilter: {name: $select.search,age: $select.search}">
<div ng-bind-html="person.name | highlight: $select.search"></div>
<small>
email: {{person.email}}
age: <span ng-bind-html="''+person.age | highlight: $select.search"></span>
</small>
</ui-select-choices>
</ui-select>
<p>Selected: {{multipleDemo.selectedPeople}}</p>
PLUNKER:
http://plnkr.co/edit/nngkvjiQmI44smcNGRGm?p=preview
正如您所看到的,它对于简单的字符串数组而不是对象数组是正常的
题:
如何在ui-select中使用带有对象数组的标记?
解决方法
您在标记属性中缺少函数名称.
尝试
tagging=”tagTransform”
然后在控制器范围中添加tagTransform函数
$scope.tagTransform = function (newTag) {
var item = {
name: newTag,email: newTag+'@email.com',age: 'unkNown',country: 'unkNown'
};
return item;
};
http://plnkr.co/edit/7fSAKmj3pLeeTaid4pMH?p=preview