我想在angularjs(in Ionic)中实现文件上传,但得到一些问题。我读,我跑以下命令的文档以下,而在项目目录是 -FileTransfer未定义 - AngularJS
bower install ngCordova
cordova plugin add org.apache.cordova.file-transfer
然后,我添加index.html中所需的参考 -
<!-- ngCordova script -->
<script type="text/javascript" src="lib/ngCordova/dist/ng-cordova.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script type="text/javascript" src="cordova.js"></script>
然后,我注入到服务我的控制器 -
angular.module('myApp').controller('AppController', ['$scope', $cordovaFileTransfer', function ($scope, $cordovaFileTransfer)
但是,当我尝试使用它像这样 -
var fileTransfer = new FileTransfer();
fileTransfer.upload("server url", "file path", options).then(function(result)...
我得到一个错误 -
Uncaught ReferenceError: FileTransfer is not defined AppController.js:35
angular.module.controller.$scope.uploadFile AppController.js:22 (anonymous function)
n.event.dispatch jquery-2.1.3.min.js:3
n.event.add.r.handle jquery-2.1.3.min.js:3
我是新来AngularJS和不知道是怎么回事错在这里。我在这里错过了一个参考或事端吗?任何人都可以帮我解决这个问题吗?
在此先感谢。
EDIT1
这里是离子如何初始化 -
.run(function ($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
EDIT2
AppController.js代码here
什么时候初始化FileTransfer对象?我读了一些问题,即使deviceready被解雇了,一些插件可能还没有出现。否则尝试添加文件插件以及它在这里陈述:http://stackoverflow.com/questions/19544352/phonegap-new-filetransfer-is-not-defined – Blauharley 2015-03-08 18:40:17
@Blauharley我不太确定你的意思是初始化FileTransfer对象。你能指出我应该在哪里检查? – Sam 2015-03-08 18:51:49
忘记这一点,我不认为这是你的错误信息的问题。你在安装文件插件后再试一次吗? – Blauharley 2015-03-08 18:54:04