0

I am using ng-repeat in my html to display the title of each 'workbook' object in an array that is on the scope. For some reason, the third title is being displayed three times. There are three objects in this test list, so it is iterating through the correct number of times. Here is the template html code:

  <div id="list-of-workbooks" ng-controller="TableauListCtrl" class="ng-scope" >
    <ul>
        <li ng-repeat="workbook in workbooks" ng-click="clickWorkbook(workbook)" ng-mouseover="mouseoverWorkbook(workbook)" class="ng-binding"> {{ workbook.getTitle() }} </li>
    </ul>
  </div>

The output looks like this:

Workbook 3 Title
Workbook 3 Title
Workbook 3 Title

Is my error in the syntax? Thanks!

EDIT: It is also possible that the error occurs when the list is made. Each title is read from an XML Document (that long chain of calls returns the correct title) and is used to set the title of a Workbook (a custom service), which is then added to the list. Are there any error in this code? It is from the application module.

        var title;
        var workbooks = [];
        for (var i = 0; i < workbooksData.length; i++) {
            var workbook = Workbook;
            title = workbooksData[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
            workbook.setTitle(title);
            workbooks[i] = workbook; // add a workbook with each title to the array of Workbooks
        }
        return workbooks;

Could it have something to do with the way angular listens to changes in the model, as is suggested in this question's accepted answer, in the second bullet point? That is pretty beyond my scope of understanding, so if someone could point me in the right direction to learn more I would appreciate it!

Community
  • 1
  • 1
Emma
  • 35
  • 2
  • 11

1 Answers1

1

Try removing spaces from your div's id attribute "List of Workbooks".

You could have: <div id="list-of-workbooks" ...>

Also, take a look at: What are valid values for the id attribute in HTML?

Community
  • 1
  • 1
slider
  • 12,810
  • 1
  • 26
  • 42