2016-01-25 83 views
0

爲什麼ng-repeat不能與給定的數據一起工作?我知道它與在數據之前加載的視圖有關。但是我根據用戶輸入填充selectedCourses數組,並且視圖顯示數組已填充,但是ng-repeat div卻什麼都沒有!請幫忙。ng-repeat不顯示信息

<br /> 
    Matches {{ matches }} 

    <br /> 
    hits {{ hits }} 

    <br /> 
    selected Courses: {{selectedCourses}} 
    <br /> 

    <div ng-repeat = "selCourse in selectedCourses" > 
    <h3> {{selCourse}} </h3> 
    </div> 

<br /> 
<label class="control-label">Search Class to Add </label> 
<input placeholder = "Enter a class" ng-model = "courseInput" type="text" class="form-control" id="courseInput"> 

所以HTML應重複selectedCourses數組作爲H3頭中的信息,但它顯示什麼! Check out this picture

是否需要重新加載視圖的ng-repeat部分?

回答

4

這是因爲你有重複的陣列中( 「ENGR 170(31237)」 我看到的圖片),儘量使用track by $index

ng-repeat="selCourse in selectedCourses track by $index"