我从firebase db获取数据并使用ng-repeat对象数组。但是虽然控制台显示正确的数据,但ng-repeat没有按预期工作。十次,当我启动服务器时,ng-repeat以某种方式工作。
我无法弄清楚加载时的错误。
控制器 -
.controller('dashboardHomeController',['$scope','$firebaseObject',
function($scope,$firebaseObject){
console.log($scope.prgList);
var programsRef = firebase.database().ref('/programs');
//fetching 50 latest programs added in db chronologically sorted
programsRef.limitToLast(50).on("value",function(snapshot){
var programsObj = snapshot.val();//setting variable to hold object of objects snapshot
var programsKeyArray = Object.keys(programsObj);//returns only keys
var programsArray = Object.values(programsObj);//returns array of values
var programsObjlength = programsKeyArray.length;
console.log(programsKeyArray,programsObjlength,programsArray);
//setting ng-repeat list prgList
$scope.prgList = programsArray;
console.log($scope.prgList);
});
}])
html -
<div class="col-sm-9">
<ul class="list-unstyled">
<li ng-repeat="prog in prgList">
<div class="row" style="border-bottom:1px solid #d7d7d7;padding-top:20px">
<div class="col-sm-2">
<img src="">
</div>
<div class="col-sm-8">
<h4>{{prog.prgHeading}}</h4>
<p>{{prog.prgSubHeading}}</p>
<p>{{prog.prgLikes}}</p>
</div>
<div class="col-sm-2" style="text-align:center">
<p>{{prog.prgStatus}}</p>
</div>
</div>
</li>
</ul>
</div>
console -
Array [ "-KolrsdHOBNavsAJZzZC", "-KolsZZeoP2hEsnG_iTd", "-Kolt9ds9SnzSmS71t88", "-KoltuJvBLSZyqsBRYnl", "-KoluUt6Vr5YlMOG4SHG" ] 5 Array [ Object, Object, Object, Object, Object ] app.js:247:17
Array [ Object, Object, Object, Object, Object ]
答案 0 :(得分:0)
似乎没有触发角度摘要周期,你应该尝试$ scope。$ apply()