我对角质和nedb还不熟悉。我试着用一个来自nedb的数组来重复。我不明白为什么我的代码不起作用
<div ng-repeat="hello in helloworld"></div>
...
hellodb.find({}).sort({helloworld: 1}).exec(function (err, docs){
$scope.helloworld = docs;
console.log($scope.helloworld);
});如果我对具有与数据库相同内容的json文件执行相同的操作
$http.get('helloworld.json').success(function(data) {
$scope.helloworld = data;
console.log($scope.helloworld);
});控制台中的输出是相同的,并且ng-重复工作。
发布于 2014-05-07 22:14:05
你试过使用$scope.$apply()吗?当您调用一些经典的角异步函数(如$http.get() )时,将自动调用$scope.$apply()。我猜这就是为什么它只在你的第二个例子中起作用,而不是在第一个。尝试在回调中的$scope.helloworld赋值后添加它。阅读这获取更多信息。
https://stackoverflow.com/questions/23526554
复制相似问题