[英]CordovaApp - AngularJs - app.initialize() -> undefined is not a function
[英]Do I need to add app.initialize() in all my html files in a cordova/phonegap project
我正在制作一個phonegap / cordova項目。 我使用命令行創建了一個骨架項目,因為指南建議制作一個新的android / phonegap項目。
在創建的index.html文件中,有一段代碼app.initialize()
,代碼來自一個名為index.js的文件。
我的問題是,我是否必須在我的所有html文件中都有這段代碼,因為我將使用jQueryMobile來執行前端,我可能需要有幾個html文件。
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
由於所有頁面都是通過Ajax調用調用的,理論上您不需要在所有頁面中添加該行。 但在某些情況下,您可能希望添加它,例如,如果可能無法從ajax調用調用特定頁面,或者由於某些奇怪的原因而導致用戶登陸該頁面而不是索引頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.