Vikas Singhal
Vikas Singhal

Reputation: 836

IndexedDB callback not updating UI in angularjs

I am using the following library to access IndexedDB in Angularjs on a new Chrome App: https://github.com/aaronpowell/db.js

When I try to update the UI on App startup by using this :

db.orders.query().all().execute().done(function(results) { 
        $scope.ordercount = results.length;
});

in my main.html I have used the ordercount variable as:

Orders : {{ordercount}}

However, the UI is not updating unless I do ng-click or any other ng-* events. All I need is to show number of orders when my app is loaded. I tried $scope.apply(), but it throws error saying apply() is not available.

Please help.

Upvotes: 2

Views: 706

Answers (2)

Chickenrice
Chickenrice

Reputation: 5727

It seems like you access $scope from out side of the angular world. You should get scope object first if you want to notify angular that the data had been updated.

//assume you have a controller named "dbCtrl" e.g., <div id="container" ng-controller="dbCtrl"></div>
angular.element($("#container")).scope().$apply(function(){
  $scope.ordercount = result.length;
});

Hope this is helpful.

Upvotes: 0

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21366

Since you are getting the values from out side of the angular js you need to do it like this,

$scope.$apply(function(){
  $scope.ordercount = results.length;
})

Upvotes: 2

Related Questions