Javascript AngulasJS、OnsenUI、Phonegap、警报在控制器内显示两次
我正在编写一个结合OnsenUI的AngulasJS应用程序,并使用phonegab将其封装在android应用程序容器中 当我的应用程序作为一个新的应用程序进程运行时,问题就开始了,它会显示两次警报框。 我完全不知道为什么。。。有什么想法吗 我的应用程序有一个application.js文件,它是整个angularJS应用程序的实际引导,MainController.js是我的代码逻辑开始的“第一个”控制器 您可以在github上找到所有代码: 注意:我还尝试将此控制器内部的代码包装到Javascript AngulasJS、OnsenUI、Phonegap、警报在控制器内显示两次,javascript,android,angularjs,cordova,onsen-ui,Javascript,Android,Angularjs,Cordova,Onsen Ui,我正在编写一个结合OnsenUI的AngulasJS应用程序,并使用phonegab将其封装在android应用程序容器中 当我的应用程序作为一个新的应用程序进程运行时,问题就开始了,它会显示两次警报框。 我完全不知道为什么。。。有什么想法吗 我的应用程序有一个application.js文件,它是整个angularJS应用程序的实际引导,MainController.js是我的代码逻辑开始的“第一个”控制器 您可以在github上找到所有代码: 注意:我还尝试将此控制器内部的代码包装到 on
ons.ready(function() {
// But this had no effect on my alert, still twice ... :-(
})();
但下面是调用我的警报的简短片段:
(function (app) {
'use strict';
app.controller('MainController', ['$scope', 'authService', function ($scope, authService) {
//Retreive a object from localstorage
$scope.authentication = authService.authentication;
//This is shown twice for an odd reason?
alert("isAuth: " + $scope.authentication.isAuth + " / username: " + $scope.authentication.userName);
//Figure out which page to show
if (page.name == "") {
if ($scope.authentication.isAuth) {
_RedirectToMain();
} else {
$scope.mainNavigation.pushPage("views/login.html", {
animation: 'none',
onTransitionEnd: function() {}
});
}
}
// More code is here below, but not related to the issue (or not that i suspect it to be)
})(application);
搜索数小时后解决:-) 我提出了这个解决方案:
var app = {
// Application Constructor
initialize: function() {
window.application = window.angular.module('Gloss', ['onsen']);
this.bindEvents();
},
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', 'online', 'pause' and etc
bindEvents: function() {
document.addEventListener('load', this.onLoad, false);
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onLoad: function() {
},
// deviceready Event Handler
onDeviceReady: function() {
// If you like to have a splashscreen... (not needed for the solution, its fancy however)
var parentElement = document.getElementById('deviceready');
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
//Device is ready, load angularjs into the dom
window.angular.bootstrap(document,['Gloss']);
}
};
app.initialize();
整个代码可在以下网站上获得:
确保按正确顺序加载onsenui、angular和cordovo。
只需查看我的github index.html。我在github中检查了您的代码,但在MainController.js中找不到任何代码。对不起,我想在调试时编辑我的代码。。。。它使用github进行自动构建……那么?问题解决了吗?如果没有,我也想看看。你能为我和其他可能想帮助你查看代码的人提供一种方法吗?是的,现在已经解决了。看一看我的最后一篇文章,或者潜入github。我仍然需要恢复我的主控制器以进行身份验证,但只需遵循gitub即可。很高兴听到这个消息。祝你好运