我想在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