ngTagsInput“ngrepeat:dupes”和“无法读取属性'替换'未定义”

时间:2014-07-31 04:02:41

标签: angularjs ng-tags-input

我正在尝试在ngTagsInput中使用自动完成功能,我收到以下错误:

Error: [ngRepeat:dupes] http://errors.angularjs.org/1.2.9/ngRepeat/dupes?p0=item%20in%20suggestionList.items%20track%20by%20track(item)&p1=undefined
    at Error (native)

OR

TypeError: Cannot read property 'replace' of undefined
    at j (https://localhost:3000/js/plugins/ng-tags-input.min.js:1:5556)

我已经检查了几次,我的查询功能正在返回一个正确的标签数组,而且确实如此。它工作得很漂亮。标签的结构如下所示:

{ 
name: String, 
_id: ObjectId, 
__v: Number, 
active: Boolean, 
display: Boolean, 
createDate: Date
}

我的HTML看起来像:

<tags-input
    ng-model="tags"
    displayProperty="name"
    placeholder="Add a tag">
    <auto-complete source="loadTags($query)"></auto-complete>
</tags-input>

我的loadTags函数是:

$scope.loadTags = function(query) {

    return $http.get(configService.getApi() + '/tags?conditions=' + urlEncodeObject({name: { $regex: query }}), {
        headers: {
            'x-auth-token': sessionService.getToken()
        }
    });
};

4 个答案:

答案 0 :(得分:5)

displayProperty应该是display-property。卫生署!

答案 1 :(得分:1)

Dupes - 它表示ngRepeat的索引是重复的。 你必须使用像

这样的smth

ng-repeat="item in items track by $index"

答案 2 :(得分:1)

// ng-repeat not check [key-property="text"]
// <tags-input ng-model="ruzhu_ids"  class="ui-tags-input"   placeholder=" "  
// add-from-autocomplete-only="false"
// key-property="text"
// > 
// </tags-input>	
// before you change tags,check dup self ,make text unique 
var can_add_tag = true;
angular.forEach($scope.ruzhu_ids, function(data, index) {
  if (data.text == result.text) {
    can_add_tag = false;
  }
});
if (can_add_tag) {
  $scope.ruzhu_ids.push(result);
}

答案 3 :(得分:0)

在标签输入上添加key-property =&#34; key&#34;其中键值对每个对象都是唯一的。

<tags-input
    ng-model="tags"
    displayProperty="name"
    key-property="id" /* here id is a key with unique value */
    placeholder="Add a tag">
    <auto-complete source="loadTags($query)"></auto-complete>
</tags-input>