Javascript cordova.js之前的angular.js会导致angular.js中出现未处理的异常
我正在使用Visual Studio 2015创建一个跨平台的平板电脑应用程序。当我在angular.js之前使用cordova.js时,效果很好Javascript cordova.js之前的angular.js会导致angular.js中出现未处理的异常,javascript,angularjs,node.js,cordova,ngcordova,Javascript,Angularjs,Node.js,Cordova,Ngcordova,我正在使用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
<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之前
现在,我在第3400行第9列收到错误消息“Unhandled exception”(未处理的异常),单位为毫秒-appx://io.cordova.myapp4934a5/www/scripts/frameworks/angular.js."
我从html标签中删除了ng应用程序,并手动引导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>
var pgapp={
初始化:函数(){
这是bindEvents();
},
//绑定启动时所需的任何事件。常见事件包括:
//“加载”、“deviceready”、“脱机”和“联机”。
bindEvents:函数(){
if(navigator.userAgent.match(/(iPhone | iPod | iPad | Android | BlackBerry | IEMobile)/){
文件.addEventListener('devicerady',this.ondevicerady,false);
}否则{
this.ondevicerady();//浏览器!
}
},
onDeviceReady:函数(){
if(窗口设备){
console.log('Running Cordova'+window.device.Cordova);
}
元素(文档).ready(函数(){
引导(文档,['firstApp']);
});
}
};
在页面末尾加载以下内容
<script type="text/javascript">
pgapp.initialize();
</script>
pgapp.initialize();
我是安格拉斯和科尔多瓦的新手。请帮忙 试试下面的代码我在你的代码中看到的是,你正在等待一个文档准备就绪,而你不应该这样做,因为OnDevicerady是该文档的cordova等价物,所以只需删除文档准备就绪时的angular
<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>
var pgapp={
初始化:函数(){
这是bindEvents();
},
//绑定启动时所需的任何事件。常见事件包括:
//“加载”、“deviceready”、“脱机”和“联机”。
bindEvents:函数(){
if(navigator.userAgent.match(/(iPhone | iPod | iPad | Android | BlackBerry | IEMobile)/){
文件.addEventListener('devicerady',this.ondevicerady,false);
}否则{
this.ondevicerady();//浏览器!
}
},
onDeviceReady:函数(){
if(窗口设备){
console.log('Running Cordova'+window.device.Cordova);
}
引导(文档,['firstApp']);
}
};
应该先走一步
<script src="scripts/frameworks/angular.js"></script>
这是正确的顺序
<!-- Cordova reference, this is added to your app when it's built. -->
<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="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
应按以下顺序加载:angular.js、ng-cordova.js、cordova.js 如果你愿意,这里有一个有效的种子:
<!-- Cordova reference, this is added to your app when it's built. -->
<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="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>