jBenes / angular-imgcache.js

Simple imgcache.js wrapper for AngularJS
MIT License
83 stars 42 forks source link

Error on $init - Ionic #4

Closed pedroabreu closed 1 month ago

pedroabreu commented 9 years ago

Hi guys,

Just trying out this directive but I've run into this issue. I'm getting this error in the console:

Error: undefined is not a function (evaluating 'window.requestFileSystem(t.getCordovaStorageType(ImgCache.options.usePersistentCache),0,o,a)')

I'm using ionic and I followed everything stated on the docs. All imgcache js files on the index.html, ImgCacheProvider on the .config and $init on the .run

.config(function (... , ImgCacheProvider) {
    'use strict';
    ...
    ImgCacheProvider.setOptions({
        debug: true,
        usePersistentCache: true
    });

    // ImgCache library is initialized automatically,
    // but set this option if you are using platform like Ionic -
    // in this case we need init imgcache.js manually after device is ready
    ImgCacheProvider.manualInit = true;

}).run(function (..., ImgCache) {

    'use strict';
...
    $ionicPlatform.ready(function () {
        ...
        ImgCache.$init();
    });
});
okonon commented 9 years ago

@pedroabreu i just set up my project to use this great library. I would suggest to check the following:

  1. make sure you have added a script tack pointing to angular-imgcache.js
  2. add Image ImgCache import to your app module['ionic','ngcordova', 'ImgCache']
  3. inject ImgCache in any controller/service where you are using teh lib
pedroabreu commented 9 years ago

Managed to figure out the issue. I was testing it on a native app (Ionic) and the problem was that I didn't had the file plugins installed. Thanks for your help. Works ok in the web version.

simpixelated commented 9 years ago

I'm getting the same problem on iOS and I have the required plugins installed (I think):

<feature name="Device">
    <param name="id" value="org.apache.cordova.device" />
    <param name="version" value="0.3.0"/>
  </feature>
  <feature name="File">
    <param name="id" value="org.apache.cordova.file" />
    <param name="version" value="1.3.3"/>
  </feature>
  <feature name="File Transfer">
    <param name="id" value="org.apache.cordova.file-transfer" />
    <param name="version" value="0.4.5"/>
  </feature>

Also calling ImgCache.$init() inside $ionicPlatform.ready I get the same error:

TypeError: undefined is not a function (evaluating 'window.requestFileSystem(t.getCordovaStorageType(ImgCache.options.usePersistentCache),0,o,a)')

I'm sure I'm missing something obvious, I just don't know what it is.

simpixelated commented 9 years ago

Fixed this. Was definitely an issue of not fulling reading the documentation. In case anyone else runs in into the same issue, the solution was to add this to your angular config: ImgCacheProvider.manualInit = true; otherwise it will init on it's own before $ionicPlatform.ready

daphnawegner commented 9 years ago

I am also seeing a similar error using ionic:

TypeError: undefined is not a function (evaluating 'window.requestFileSystem(Helpers.getCordovaStorageType(ImgCache.options.usePersistentCache), 0, _gotFS, _fail)')

I have followed the all the steps in the docs but still getting the error.

daphnawegner commented 9 years ago

I tracked the error to this line (called from the init function):

if (Helpers.isCordova()) { // PHONEGAP window.requestFileSystem(Helpers.getCordovaStorageType(ImgCache.options.usePersistentCache), 0, _gotFS, _fail);

in imgCache.js line 545. Anyone else had this problem?

danielrys commented 9 years ago

Had the same problem, turned out that I was setting manual init in a wrong way (with the setOption function)

ImgCacheProvider.setOptions({ manualInit: true });

fixed it by changing it to

ImgCacheProvider.manualInit = true;

Make sure you don't make the same mistake.

zycbobby commented 9 years ago

I think I also met this problem, the console outputs

"window.requestFileSystem(Helpers.getCordovaStorageType(ImgCache.options.usePersistentCache), 0, _gotFS, _fail);"

My config part is

.config(function ($stateProvider, $urlRouterProvider, ImgCacheProvider) {

        // more options at once
        ImgCacheProvider.setOptions({
            debug: false,
            usePersistentCache: true
        });

        // ImgCache library is initialized automatically,
        // but set this option if you are using platform like Ionic -
        // in this case we need init imgcache.js manually after device is ready
        ImgCacheProvider.manualInit = true;

    });

and init


.run(function ($ionicPlatform, updateService, $ionicPopup, $timeout, ImgCache) {
        $ionicPlatform.ready(function () {
            ImgCache.$init();
        });
    })