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

Tagged with:  

21 Responses to Duplicates in a repeater are not allowed in AngularJS

  1. webnet668 says:

    Thanks, just what I needed!! I wish your commends used G+ logins

  2. Ofer Groman says:

    You’re a life-saver.

  3. Esteban López A. says:

    Ohhh!! thank you so much,
    You saved my life.!

  4. Sipho Mfungi says:

    Great solution. Thanks! It’s silly that Angular has this bug

  5. Gluten says:

    This solution doesn’t work for me 🙁

  6. but in my case if i used track by $index then data repeatedly displayed. how we can avoid such thing

  7. Thanks you its helped a lot..

  8. ovack says:

    thanks

  9. Sachin says:

    thanks bro…
    saved my day..

  10. Brilliant tip… thanks so much!

  11. onozor says:

    Thanks a million this save my life

  12. Mario Alberto Dos Santos says:

    Love You

  13. Vithika says:

    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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2011 Anuj Gakhar