Cordova:LocalFileSystem未定义 [英] Cordova: LocalFileSystem is not defined

查看:1479
本文介绍了Cordova:LocalFileSystem未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获得cordova文件系统的工作。我有一个项目与以下依赖项:

I am not able to 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"

app.js 我定义了一个控制器模块的依赖:

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);
  }
}

我得到的是:

LocalFileSystem is not defined

requestFileSystem 未定义可能是此行为的原因是什么?

Also, requestFileSystem is undefined. What could be the reason for this behavior?

我使用cordova 4.1.2和离子1.3.1。

I am using cordova 4.1.2 and ionic 1.3.1.

编辑:这是根据html标记:

This is the according 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>


推荐答案

您不需要等待 deviceReady 事件,因此文件插件尚未加载。更改

You simply aren't waiting for deviceReady event to be fired and thus the File plugin isn't loaded yet. Change

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

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

即使在此之后, LocalFileSystem.PERSISTENT 我在模拟等),但它可以替换为 1 ,因为它只是一个常数。

The LocalFileSystem.PERSISTENT might be undefined even after that (has been for me while emulating etc.) but it can be replaced with 1 as it is just a constant.

这篇关于Cordova:LocalFileSystem未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆