2014-05-07 17 views
0

我是新來的角和nedb。我試圖從一個nedb的數組中使用ng-repeat。 我不明白爲什麼我的代碼不工作使用nedb數組進行ng-repeat

<div ng-repeat="hello in helloworld"></div> 

... 
hellodb.find({}).sort({helloworld: 1}).exec(function (err, docs){ 
     $scope.helloworld = docs; 
     console.log($scope.helloworld); 
}); 

如果我做同樣的用相同的內容數據庫

$http.get('helloworld.json').success(function(data) { 
     $scope.helloworld = data; 
     console.log($scope.helloworld); 
}); 

json文件,在控制檯輸出是相同和ng-repeat作品

回答

3

您是否嘗試過使用$scope.$apply()?當你打電話給一些經典的角度異步功能,如$http.get()$scope.$apply()在最後自動調用。我猜這就是它只在你的第二個例子中起作用的原因,而不是第一個例子。嘗試在回調中分配$scope.helloworld後添加它。閱讀this瞭解更多信息。

+1

非常感謝!它一直在困擾着我幾個小時..對於將來的引用,它是$ scope。$ apply() – user3320468