bramski / angular-indexedDB

An angularjs serviceprovider to utilize indexedDB with angular
165 stars 49 forks source link

Adds then retrieves first time. Can't retrieve second time #60

Closed seanmavley closed 8 years ago

seanmavley commented 8 years ago

Kindly see this snippet in the README: `angular.module('myModuleName') .controller('myControllerName', function($scope, $indexedDB) {

$scope.objects = [];

$indexedDB.openStore('people', function(store){

  store.insert({"ssn": "444-444-222-111","name": "John Doe", "age": 57}).then(function(e){...});

  store.getAll().then(function(people) {  
    // Update scope
    $scope.objects = people;
  });
});

});`

The store.getAll() should probably come out of that indexedDB.openStore(....) { ... } block.

When I tried the above snippet, the objects are added on first time, if the db doesn't exist, but subsequent ones, no retrieval happens

I did this and it works fine:

$indexedDB.openStore('myStop', function(store) {
            store.getAll().then(function(data) {
                // Update scope
                $scope.objects = data;
            });
        });
bramski commented 8 years ago

You have no catch. Are you sure the first function succeeds a second time? You're using insert and not upsert so perhaps the insert is failing due to a key clash but you're not seeing the transaction error. I'm guessing that ssn is your key property?

Try putting together a gist if that fails. On Apr 1, 2016 6:33 AM, "Nkansah Rexford" notifications@github.com wrote:

Kindly see this snippet in the README: `angular.module('myModuleName') .controller('myControllerName', function($scope, $indexedDB) {

$scope.objects = [];

$indexedDB.openStore('people', function(store){

store.insert({"ssn": "444-444-222-111","name": "John Doe", "age": 57}).then(function(e){...});

store.getAll().then(function(people) { // Update scope $scope.objects = people; }); });

});`

The store.getAll() should probably come out of that indexedDB.openStore(....) { ... } block.

When I tried the above snippet, the objects are added on first time, if the db doesn't exist, but subsequent ones, no retrieval happens

I did this and it works fine:

$indexedDB.openStore('myStop', function(store) { store.getAll().then(function(data) { // Update scope $scope.objects = data; }); });

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/bramski/angular-indexedDB/issues/60

seanmavley commented 8 years ago

Yep, true. I'm using insert function, and without an error function. And yes, there's a key clash. However, it isn't clear from the docs, with the insert embedded in the openStore block. Might be confusing for newbies like myself when they realize insert worked, but results doesn't show the second time.

Not a bug report, but just a doc clarification

bramski commented 8 years ago

Feel free to make an addition to the Readme you feel would be helpful. On Apr 1, 2016 7:05 AM, "Nkansah Rexford" notifications@github.com wrote:

Yep, true. I'm using insert function, and without an error function. And yes, there's a key clash. However, it isn't clear from the docs, with the insert embedded in the openStore block. Might be confusing for newbies like myself when they realize insert worked, but results doesn't show the second time.

Not a bug report, but just a doc clarification

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/bramski/angular-indexedDB/issues/60#issuecomment-204408773