AngularJS does not allow duplicates in a ng-repeat directive. This means if you are trying to do the following, you will get an error.
[js]
// the below will throw an error
Error: Duplicates in a repeater are not allowed. Repeater: row in [1,1,1] key: number:1
<div ng-repeat="row in [1,1,1]">[/js]
However, changing the above code slightly as below will get it working again.
[js]
// this will work
<div ng-repeat="row in [1,1,1] track by $index">[/js]
The credit for the fix goes to comments in this thread https://github.com/angular/angular.js/pull/2505
Thanks, just what I needed!! I wish your commends used G+ logins
You’re a life-saver.
Ohhh!! thank you so much,
You saved my life.!
Great solution. Thanks! It’s silly that Angular has this bug
This solution doesn’t work for me 🙁
Hi Gluten, what error do you get?
but in my case if i used track by $index then data repeatedly displayed. how we can avoid such thing
I solved it out
And how???
Seriously, what do you expect from an anwser like this? You have been here to get some help, so be kind enough to give others help as well!
Thanks you its helped a lot..
thanks
thanks bro…
saved my day..
Brilliant tip… thanks so much!
[…] The solution is actually described here: https://www.anujgakhar.com/2013/06/15/duplicates-in-a-repeater-are-not-allowed-in-angularjs/ […]
[…] The solution is actually described here: https://www.anujgakhar.com/2013/06/15/duplicates-in-a-repeater-are-not-allowed-in-angularjs/ […]
[…] The solution is actually described here: https://www.anujgakhar.com/2013/06/15/duplicates-in-a-repeater-are-not-allowed-in-angularjs/ […]
Thanks a million this save my life
Love You
In my case..if i create a duplicate name ,it does not get stored..that works fine..but I want to throw error message at the time of creation only..when the values is duplicate how to throw error message to the user after clicking of submit button.
[…] The solution is actually described here: https://www.anujgakhar.com/2013/06/15/duplicates-in-a-repeater-are-not-allowed-in-angularjs/ […]
[…] The solution is actually described here: https://www.anujgakhar.com/2013/06/15/duplicates-in-a-repeater-are-not-allowed-in-angularjs/ […]