ngTagsInput
ngTagsInput copied to clipboard
Getting duplicates in a repeater are not allowed - how can I use track by $index.
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,
same issue here, what should be done ?
Use key-property!
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!
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.
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 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.
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