سؤال

I'm new to angular and nedb. I'm trying to use an array from a nedb for ng-repeat. I don't understand why my code don't work

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

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

If i do the same with a json file with the same content as the database

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

the output in the console is the same, and ng-repeat works

هل كانت مفيدة؟

المحلول

Have you tried using $scope.$apply()? When you're calling some classic angular async function such as $http.get(), $scope.$apply() is called at the end automatically. I'm guessing that's the reason it works only in the second example of yours and not in the first. Try adding it after the assignment of $scope.helloworld in the callback. Read this for more info.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top