0

I wrote a simple ng-repeat example using Onsen-UI, it works great (see my codepen) but it doesn't work when I add more variable in var city

Update #1

JS

    var city=[...'Kumbakonam','Kumily']; //Works

but if i add more variables, like

var city=[...'Kumbakonam','Kumily','city','city','city','city','city','city','city','city','city','city','city']; //Not Works

Codepen that works

Codepen that doesn't

Am i missing something or is it a limitation or something like that. Please explain.

Thank you guys.

Ranjith Varatharajan
  • 1,596
  • 1
  • 33
  • 76
  • What do you mean by add more variable in var city? Can you showcase the issue in codepen. In this fork click on add and it will add the item.. http://codepen.io/anon/pen/qEmjyN – PSL Jan 20 '15 at 05:25
  • Thanks @PSL for the response. I have edited my question, See Update #1. and yes, your codepen works but i need it to be static, initialise it first and then display the result. – Ranjith Varatharajan Jan 20 '15 at 05:35
  • 1
    That is because you have duplicates in ng-repeat, you should wither use array of objects or use track by $index. http://codepen.io/anon/pen/WbjOgY – PSL Jan 20 '15 at 05:37
  • possible duplicate of [Angular ng-repeat Error "Duplicates in a repeater are not allowed."](http://stackoverflow.com/questions/16296670/angular-ng-repeat-error-duplicates-in-a-repeater-are-not-allowed) – PSL Jan 20 '15 at 05:41
  • It works. Simple mistake learned today. Thanks @psl. – Ranjith Varatharajan Jan 20 '15 at 05:42

1 Answers1

1

You should use the console while developing. It shows what's wrong:

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: list in cityList, Duplicate key: string:City, Duplicate value: "City"

You aren't allowed to repeat values in the ngRepeat directive.

Andreas Argelius
  • 3,604
  • 1
  • 13
  • 22