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.

// 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]">

However, changing the above code slightly as below will get it working again.

// this will work
<div ng-repeat="row in [1,1,1] track by $index">

The credit for the fix goes to comments in this thread https://github.com/angular/angular.js/pull/2505

Tagged with:  

19 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. Sachin says:

    thanks bro…
    saved my day..

  9. Brilliant tip… thanks so much!

  10. onozor says:

    Thanks a million this save my life

  11. Mario Alberto Dos Santos says:

    Love You

  12. 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

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 445 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: