ng-repeat: One-item-only source

一曲冷凌霜 提交于 2019-12-25 06:50:24

问题


This is my code:

app.js

$http.get("http://angularjs.uum.my/tt.json")
.success(function(response) {$scope.scrollItems = response;});

$http.get("http://angularjs.uum.my/tt2.json")
.success(function(response) {$scope.scrollItems2 = response;});

tt.json - have only 1 element

  1. http://angularjs.uum.my/app/#/timetable

tt2.json - have two 2 elements

  1. http://angularjs.uum.my/app/#/timetable2

The problem is with page no. 1, where only one element exist, the page rendered empty list repeating x number of times (where x equal to number of child elements)

Is this known bug? How to solve this problem if the number of elements is unknown beforehand to the developer?

Please help, thanks for your time.


回答1:


That is not a bug, your first json is

{"namakursus":"John", "pensyarah":"Doe", "yeh":"yeh"}

and the second one is

[
    {"namakursus":"John", "pensyarah":"Doe", "yeh":"yeh"},
    {"namakursus":"John2", "pensyarah":"Doe2", "yeh":"yeh2"}
]

this means the first one is not an array, so it is reapiting an object

if you want to get the same behavior your json should be and array with only 1 element, not an single object

[{"namakursus":"John", "pensyarah":"Doe", "yeh":"yeh"}] 


来源:https://stackoverflow.com/questions/27085625/ng-repeat-one-item-only-source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!