8

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)

また

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

4 に答える 4

0

tags-input に key-property="key" を追加します。キー値は各オブジェクトに固有です。

<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>
于 2016-12-15T14:00:01.460 に答える