Tom Hanson
Tom Hanson

Reputation: 935

AngularJS ng-repeat not repeating

I am learning Angular JS and I am building a small app.
The first part of the app you can type in the words and it will place each word into a different array and display them in a <ol> list.
That part works...
The second part to it, I want to use the to choose how many words there are and then place "" as temp words in array for the amount of words there are.
The code is putting the "
" into the array as the array length is increasing, but the ng-repeat for the second <ol> only shows the first element and then stops. when the number box changes it calls this function.

$scope.createTempWords = function(){
    this.knownWords = [];
    var tempString = "";
    for(var i = 0; i<this.wordCount2; i++)
    {
        tempString += "_";
        if(i < this.wordCount2-1)
            tempString += " ";
    }
    this.knownWords = tempString.split(" ");
    this.count = this.knownWords.length;
}

the ng-repeat is link to knownWords.

The full code can be seen here http://codepen.io/SighFye/pen/bpGzwZ

Why doesn't the second ng-repeat do its job?

Upvotes: 0

Views: 391

Answers (1)

Omri Aharon
Omri Aharon

Reputation: 17064

Several errors in the codebin:

  1. You load Angular twice. (doesn't cause your error, just an FYI)
  2. You have duplicates alert, you need to use track by $index on your ng-repeat.

Codebin

Upvotes: 1

Related Questions