ngTagsInput icon indicating copy to clipboard operation
ngTagsInput copied to clipboard

Getting duplicates in a repeater are not allowed - how can I use track by $index.

Open mnomanali opened this issue 10 years ago • 7 comments

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: item in suggestionList.items track by track(item), Duplicate key: undefined,

mnomanali avatar Jul 27 '15 15:07 mnomanali

same issue here, what should be done ?

arvind-das avatar Jul 31 '15 17:07 arvind-das

Use key-property!

kimcrab avatar Aug 01 '15 04:08 kimcrab

Thanks for your reply.I also looked at the js. @mnomanali you can use these properties. If you have json data like this

[{name:"cat",id:"2"}]

then you can remove dupes error by using

key-property="id"

and to display tag names you should use

display-property="name"

It worked for me. Cool!

arvind-das avatar Aug 01 '15 15:08 arvind-das

One way to fix it is by editing the source code, this is hackish so hopefully the author sees this. But line 1143 contains ng-repeat="item in suggestionList.items track by track(item). If you change track by track(item) to track by $index, it works.

danielyaa5 avatar Aug 18 '15 02:08 danielyaa5

Sorry for not replying sooner.

As @KimCrab and @arvind-das said, using keyProperty is the correct way to handle this particular case. Although that option is documented, I recognize common scenarios like this one should be better addressed in the docs. I'll try to fix that.

mbenford avatar Sep 28 '15 13:09 mbenford

@mbenford Why dont you merge this commit in: https://github.com/wizbii/ngTagsInput/commit/6ef8959abcaaf545d743dfab5c0cbe46903acef8

Even using keyProperty still getting issues and really wanna use my custom track by expression.

samuelcastro avatar Mar 31 '17 19:03 samuelcastro

I suppose the problem is related to the object structure. My id and label properties are nested to an external level: [{ level_1: { id: 1, my_label: 'test1 } }, { level_1: { id: 2, my_label: 'test2' } }]

If I set my key-property with 'level_1.id', it throws the duplicate exception. However, if I my array is [{ id: 1, my_label: 'test1 }, { id: 2, my_label: 'test2' }] everything goes fine.

Is that correct? Do I really need to suppress this external level so that it can deal with?

Thank you, Guilherme

guilhermemaranhao avatar Aug 22 '17 13:08 guilhermemaranhao