我使用Visual Studio 2015创建了一个跨平台的平板电脑应用。当我在angular.js之前有cordova.js时它工作正常。
<link href="css/bootstrap.css" rel="stylesheet" />
<link href="css/font-awesome.css" rel="stylesheet" />
<!-- Cordova reference, this is added to your app when it's built. -->
<script src="cordova.js"></script>
<script src="scripts/platformOverrides.js"></script>
<!-- AngularJS references -->
<script src="scripts/frameworks/angular.js"></script>
<script src="scripts/frameworks/angular-route.js"></script>
<script src="scripts/script.js"></script>
<script src="scripts/controllers.js"></script>
但是,我需要使用ngCordova添加电子邮件编辑器。根据ngCordova网站,我需要在cordova.js之前和AngularJS / Ionic文件之后的index.html文件中包含ng-cordova.js或ng-cordova.min.js(因为ngCordova依赖于AngularJS)。所以我把angular.js放在cordova.js之前。
现在我收到错误消息&#34; ms-appx://io.cordova.myapp4934a5/www/scripts/frameworks/angular.js."第34行第3400行的未处理异常
我从html标签中删除了ng-app并手动引导AngularJS,但这没有帮助。这是我在任何其他脚本之前放入head标签的脚本。
<script type="text/javascript">
var pgapp = {
initialize: function () {
this.bindEvents();
},
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function () {
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
document.addEventListener('deviceready', this.onDeviceReady, false);
} else {
this.onDeviceReady(); // Browser!
}
},
onDeviceReady: function () {
if (window.device) {
console.log('Running Cordova ' + window.device.cordova);
}
angular.element(document).ready(function() {
angular.bootstrap(document, ['firstApp']);
});
}
};
</script>
页面末尾加载以下内容。
<script type="text/javascript">
pgapp.initialize();
</script>
我是AngularJS和cordova的新手。请帮忙。
答案 0 :(得分:1)
您应该按以下顺序加载:angular.js,ng-cordova.js,cordova.js。
如果你愿意,这里有一个工作种子: https://github.com/marioaleogolsat/cordova-angular-angularMaterial-seed
答案 1 :(得分:0)
尝试下面的代码我在你的代码中看到的是你正在等待一个你不应该做的文件准备,因为OnDeviceready是cordova equivelant,所以只需删除文件就准备就绪了。
<script type="text/javascript">
var pgapp = {
initialize: function () {
this.bindEvents();
},
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function () {
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
document.addEventListener('deviceready', this.onDeviceReady, false);
} else {
this.onDeviceReady(); // Browser!
}
},
onDeviceReady: function () {
if (window.device) {
console.log('Running Cordova ' + window.device.cordova);
}
angular.bootstrap(document, ['firstApp']);
}
};
</script>