我正在使用 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 网站,我需要在 index.html 文件中的 cordova.js 之前和 AngularJS/Ionic 文件之后包含 ng-cordova.js 或 ng-cordova.min.js (因为 ngCordova 依赖于 AngularJS)。所以我把 angular.js 放在 cordova.js 之前。
现在我收到错误消息“在 ms-appx://io.cordova.myapp4934a5/www/scripts/frameworks/angular.js 中的第 3400 行第 9 列处出现未处理的异常。”
我从 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 的新手。请帮忙。
最佳答案
您应该按以下顺序加载:angular.js、ng-cordova.js、cordova.js。
如果你愿意,这里有一个可用的种子: https://github.com/marioaleogolsat/cordova-angular-angularMaterial-seed
关于javascript - cordova.js 之前的 angular.js 导致 angular.js 中出现未处理的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31818709/