Javascript Referenceerror:未定义cordova
首先,我创建了一个空白项目Javascript Referenceerror:未定义cordova,javascript,cordova,ionic-framework,Javascript,Cordova,Ionic Framework,首先,我创建了一个空白项目 ionic start checkGPS blank 之后我安装了插件- cordova.plugins.diagnostic 我在www/index.html中添加了以下代码 cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){ console.log("GPS location is " + (enabled ? "enabled" : "disabled")); }, f
ionic start checkGPS blank
之后我安装了插件-
cordova.plugins.diagnostic
我在www/index.html中添加了以下代码
cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){
console.log("GPS location is " + (enabled ? "enabled" : "disabled"));
}, function(error){
console.error("The following error occurred: "+error);
})
查看config.xml和package.json
插件信息已经添加,甚至我尝试添加cordova.js
但是它没有起作用
Index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link rel="manifest" href="manifest.json">
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="cordova.js"></script>
<script src="js/app.js"></script>
<script type="text/javascript">
document.addEventListener("deviceready", function() {
cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){
console.log("GPS location is " + (enabled ? "enabled" : "disabled"));
alert('hello');
}, function(error){
console.error("The following error occurred: "+error);
})
}, false);
</script>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content>
</ion-content>
</ion-pane>
</body>
</html>
document.addEventListener(“deviceready”,函数(){
cordova.plugins.diagnostic.isGpsLocationEnabled(功能已启用){
console.log(“GPS位置为”+(启用?:“禁用”);
警惕(“你好”);
},函数(错误){
console.error(“发生以下错误:“+错误”);
})
},假);
离子空白起动器
问题可能是因为设备未准备好。尝试在生命周期事件中添加代码。像这样:
document.addEventListener("deviceready", function() {
cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){
console.log("GPS location is " + (enabled ? "enabled" : "disabled"));
}, function(error){
console.error("The following error occurred: "+error);
})
}, false);
是的,我添加了…您确定在
行中没有收到404错误吗?请检查您的应用程序并检查控制台输出。您是在浏览器中测试还是在真实设备中测试?在控制台中添加cordova.js文件时没有错误。@Brunopes我也在浏览器、模拟器和真实设备上尝试过。请用完整的index.html文件更新您的问题。是的,完成,请检查