简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM