Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top