Cordoba: LocalFileSystem not defined

I cannot get the cordova file system to work. I have a project with the following dependencies:

com.ionic.keyboard 1.0.3 "Keyboard" org.apache.cordova.console 0.2.12 "Console" org.apache.cordova.device 0.2.13 "Device" org.apache.cordova.file 1.3.2 "File" org.apache.cordova.file-transfer 0.4.8 "File Transfer" 

In app.js I define a dependency on a controller module:

 angular.module('starter', ['ionic', 'controllers']); 

The controller code is basically this:

 angular.module('controllers', []) .controller('GalleryCtrl', function ($scope) { function success() {...} function error() {...} window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, success, error); } } 

What then do I get:

 LocalFileSystem is not defined 

In addition, requestFileSystem is undefined. What could be causing this behavior?

I am using cordova 4.1.2 and ionic 1.3.1.

EDIT:. This is the corresponding html markup:

 <body ng-app="starter" ng-controller="GalleryCtrl"> <ion-nav-view> <ion-slide-box id="slideBox"> <ion-slide ng-repeat="..."> <!-- details omitted --> </ion-slide> </ion-slide-box> </ion-nav-view> </body> 
+6
source share
3 answers

You simply do not expect the deviceReady event to fire, and thus the File plugin is not yet loaded. Edit

 window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, success, error); 

to

 document.addEventListener("deviceready", function() { window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, success, error); }, false); 

LocalFileSystem.PERSISTENT can be undefined even after that (it was for me at the time of emulation, etc.), but it can be replaced with 1, because it is just a constant.

+10
source

One of the reasons that requestFileSystem is unavailable is that the device is not ready.

Try to run the code after the window is ready:

 $scope.$on('$ionicView.enter', function(event, data) { window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, success, error); }); 

I get that LocalFileSystem is not defined in my editor because its plugin (from my understanding), but after loading the window I can use requestFileSystem and LocalFileSystem works as expected.

-1
source

For an ionic injection of $ionicPlatform , then use:

 $ionicPlatform.ready(function() { window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, success, error); }, false); 
-1
source

Source: https://habr.com/ru/post/981113/


All Articles