Alan Souza
Alan Souza

Reputation: 7795

Angular-indexedDB: Issues with Firefox

I'm using AngularJS and IndexedDB in my application. There is a really nice tool on GitHub that contains an AngularJS module for IndexedDB. The library is called Angular-indexedDB and is available here.

I'm facing issues when I try to open my existing application using Firefox version 31 (the latest).

When I open the console I see the following message:

TypeError: setting a property that has only a getter

Any idea how to fix this?

Upvotes: 0

Views: 651

Answers (2)

Alan Souza
Alan Souza

Reputation: 7795

I've forked the angular-indexedDB and implemented the solution using AngularJS $window instead. I also sent a pull request, hopefully it will be integrated soon.

I completely removed the first two lines that used global namespace. Then, I moved the implementation to the $get function for the indexedDB provider. Which now looks like follow:

    module.$get = ['$q', '$rootScope', '$window', function($q, $rootScope, $window) {

       if(!('indexedDB' in $window)) {
             $window.indexedDB = $window.mozIndexedDB || $window.webkitIndexedDB || $window.msIndexedDB;
       }

       var IDBKeyRange = $window.IDBKeyRange || $window.mozIDBKeyRange || $window.webkitIDBKeyRange || $window.msIDBKeyRange;
       ...

If you look here, you can find the full implementation. Just replace your existing script by this one and it should work fine in Firefox 31.

Upvotes: 1

Alan Souza
Alan Souza

Reputation: 7795

To fixed the problem I had to change the code for this library (I will send the pull request soon).

To get it working in Firefox replace line 9 from this JS file by this:

if(!('indexedDB' in window)) {
    var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
}

The fix is simple enough. If indexedDB is not in window it means that I can create the first one.

Upvotes: 0

Related Questions