我沒有太多信息,因爲這是我曾經遇到的最奇怪的問題。沒有任何變化,突然收到Ionic TypeError co.event未定義
我正在寫Ionic 2的應用程序。昨天晚上我睡覺了,一切都很好。我今天早上起牀繼續工作,即使歡迎頁面加載,當您滾動到主頁時,我得到的錯誤是co.event未定義。
下面是壯觀無益的錯誤信息的截圖(爲什麼我不能從Ionic的這個錯誤屏幕複製粘貼錯誤信息?太愚蠢了)。在我的代碼庫中搜索「co.event」會返回0個結果。
我沒有改變的一行代碼的任何地方。我甚至不明白這是如何可能的,更不用說做些什麼來解決它。
我從我正在工作的分支切換到Master分支,看看是否還好。不,這個錯誤有完全不同的錯誤,儘管這個錯誤也沒有改變。
我可以進入src/app/app.component.ts
和註釋掉這使得一切工作,但似乎是一個非常糟糕的主意,因爲這聽起來像一個非常關鍵的線,包括解決在主分支的錯誤。
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen) {
// this.initializeApp();
// used for an example of ngFor and navigation
this.pages = [
{ title: 'Welcome', component: WelcomePage },
{ title: 'Home', component: HomePage },
{ title: 'List', component: ListPage }
];
}
任何幫助非常感謝。
編輯更新:
這裏是我的initializeApp
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.splashScreen.hide();
// Enable to debug issues.
// window["plugins"].OneSignal.setLogLevel({logLevel: 4, visualLevel: 4});
var notificationOpenedCallback = function(jsonData) {
console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
};
// window["plugins"].OneSignal
// .startInit("yyyyyyyyy", "yyyyyyyyy")
// .handleNotificationOpened(notificationOpenedCallback)
// .endInit();
});
}
而這裏的第三個不同的錯誤(儘管有硬是什麼也沒有改變????),我的Android手機上運行的Dev分支的時候,而不是出現在ionic serve
。 Master分支在Android手機上運行良好。
編輯2:首頁代碼
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<h1 class="header">Nuevo Niño</h1>
<hr />
<div ng-app ng-init="qty=1;cost=2">
<button ion-button (click)="setData()">SetData</button>
<button ion-button (click)="getData()">GetData</button>
<br />
<b>Name:</b> {{name}}
<hr />
<b>Invoice:</b>
<div>
Quantity: <input type="number" min="0" ng-model="HomePage.qty">
</div>
<div>
Costs: <input type="number" min="0" ng-model="cost">
</div>
<div>
<b>Total:</b> {{qty * cost | currency}}
</div>
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed quis ipsum id libero auctor viverra eget vitae ipsum. Aenean ultrices diam odio, ac vulputate felis ultrices vel. Donec a mauris tristique, feugiat nunc nec, lacinia augue.
</p>
<ion-list>
<ion-item>
<ion-label>Expected Birth Date</ion-label>
<ion-datetime displayFormat="MMM DD YYYY" [(ngModel)]="event.month"></ion-datetime>
</ion-item>
<ion-item>
<p><b>Baby arrives {{ days_until_birth }}!</b></p>
</ion-item>
</ion-list>
<ion-list>
<ion-list-header>
Recent Notifications
</ion-list-header>
<ion-item>
<ion-avatar item-start>
<img src="assets/img/avatar-ben.png">
</ion-avatar>
<h2>Doctor Smith</h2>
<h3>24th January</h3>
<p>3 month check-up</p>
</ion-item>
<ion-item>
<ion-avatar item-start>
<img src="assets/img/avatar-han.png">
</ion-avatar>
<h2>Han</h2>
<h3>Look, kid...</h3>
<p>I've got enough on my plate as it is, and I...</p>
</ion-item>
<ion-item>
<ion-avatar item-start>
<img src="assets/img/avatar-leia.png">
</ion-avatar>
<h2>Leia</h2>
<h3>I can handle myself</h3>
<p>You will remove these restraints and leave...</p>
</ion-item>
</ion-list>
<!-- <button ion-button secondary menuToggle>Toggle Menu</button> -->
</ion-content>
和.ts文
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import moment from 'moment';
import { Storage } from '@ionic/storage';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
name: string = 'John';
// public days_until_birth = moment('20171119', 'YYYYMMDD').fromNow();
// let data = moment()
// let data = moment().format('YYYYMMDD');
// let time = moment().format('HHmmss');
// console.log('today is: ', data + ' and time: ', time);
constructor(public navCtrl: NavController, public storage: Storage) {
}
ionViewDidLoad() {
this.storage.set('name', 'James');
}
setData(){
this.storage.set('name', 'Brett');
}
getData(){
this.storage.get('name').then((data) => {
console.log(data);
});
}
}
這是在一個設備/模擬器或離子服務? initializeApp()包含什麼? –
@suraj關於離子發球。在Android設備上,master分支很好,dev分支有一個THIRD不同的錯誤。請參閱OP編輯。 – user2792268
這種情況並非你所改變的,在瀏覽器中使用插件肯定會破壞你的應用程序,因爲無法訪問插件。但是在你的主頁上有一些東西,第一個和第三個錯誤都顯示主頁上有錯誤,你能顯示你的HomePage代碼嗎?也許有些東西依賴於插件,並且因爲它們無法在網絡上使用,所以會引發錯誤。 –