(function () {
"use strict";
document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false );
function onDeviceReady() {
var app_ng=angular.module('myApp', ['ngCordova']);
console.log('device ready');
$cordovaFile.getFreeDiskSpace()
.then(function (success) {
console.log(success);
}, function (error) {
console.log(error);
});
};
} )();
<html>
<head>
<meta charset="utf-8" />
<!--
Customize the content security policy in the meta tag below as needed. Add 'unsafe-inline' to default-src to enable inline JavaScript.
For details, see http://go.microsoft.com/fwlink/?LinkID=617521
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<title>ngcordovatest</title>
<!-- ngcordovatest references -->
<link href="css/index.css" rel="stylesheet" />
</head>
<body ng-app="myApp">
<p>Hello, your application is ready!</p>
<div id="console">
</div>
<!-- Cordova reference, this is added to your app when it's built. -->
<script src="scripts/jquery.js"></script>
<script src="scripts/angular.min.js"></script>
<script src="scripts/ng-cordova.min.js"></script>
<script src="scripts/ng-cordova-mocks.min.js"></script>
<script src="cordova.js"></script>
<script src="scripts/platformOverrides.js"></script>
<script src="scripts/index.js"></script>
</body>
</html>
我总是收到以下错误:
未捕获的ReferenceError:$ cordovaFile未定义
我使用Android设备进行USB连接调试。
有什么问题?我无法弄清楚。谢谢。
答案 0 :(得分:1)
因为'angular'只是当前范围内的有用对象。所以,试试像
这样的东西 function onDeviceReady() {
.........
angular.element(document).ready(function () {
angular.element(document.body).injector().invoke(['$cordovaFile', function($cordovaFile){
$cordovaFile.getFreeDiskSpace()
.then(function (success) {
console.log(success);
}, function (error) {
console.log(error);
});
}]);
}
});