2017-03-01 23 views
0

我想使用mbenford/ngTagsInput指令如下mbenford/ngTagsInput多个标签,而不关键属性

<tags-input name="skill" ng-model="storage.skills" placeholder="specializations" 
min-tags="1" add-on-enter="true" min-length="1" key-property="id" display-property="name" required> 
    <auto-complete source="getSkillSearch($query)" highlight-matched-text="true" min-length="1"></auto-complete> 
</tags-input> 

,如果你看到我已经设置了关键属性为ID,当我加入新的标签在这里(它没有关键属性),该指令不允许我这样做多于一次。

https://github.com/mbenford/ngTagsInput/issues/509(有点非常相似),但没有解决方案。他们是一种解决方法,或者我错过了一些非常愚蠢的事情。

回答

0

有一个属性被称为onTagAdding。提供一个为添加标签创建id的功能。这里有一个例子:

HTML

<tags-input name="skill" ng-model="storage.skills" placeholder="specializations" 
min-tags="1" add-on-enter="true" min-length="1" key-property="id" display-property="name" on-tag-adding="createId($tag)" required> 
<auto-complete source="getSkillSearch($query)" highlight-matched-text="true" min-length="1"></auto-complete> 
</tags-input> 

SCRIPT

$scope.createId= function(tag) { 
    // Only do this if tag.id is undefined 
    if(angular.isUndefined(tag.id) {   
     tag.id= tag.name; // or create a random value 
    } 
};