gpt4 book ai didi

javascript - 没有改变任何东西,突然收到 Ionic TypeError co.event is undefined

转载 作者:太空宇宙 更新时间:2023-11-04 02:00:55 28 4
gpt4 key购买 nike

我没有太多信息,因为这是我遇到过的最奇怪的问题。

我正在用 Ionic 2 编写一个应用程序。昨晚我上床 sleep 时一切都很好。我今天早上起床继续工作,尽管加载了欢迎页面,但当您滚动到主页时,我收到一条错误,指出 co.event 未定义。

这是一个极其无用的错误消息的屏幕截图(为什么我不能在 Ionic 中从这个错误屏幕复制粘贴错误消息?太愚蠢了)。在我的代码库中搜索“co.event”返回 0 个结果。

Error Message

我没有在任何地方更改任何一行代码。我什至不明白这是怎么可能的,更不用说如何解决它了。

我从我正在处理的分支切换到主分支,看看是否仍然可以。不,尽管对此进行了零更改,但仍存在完全不同的错误。

enter image description here

我可以通过进入 src/app/app.component.ts 并注释掉 this.initializeApp(); 来解决 master 分支上的错误,这使得一切正常,但似乎是一个非常糟糕的主意,因为这听起来像是一个非常重要的行。

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 手机上而不是在 ionicserve 中运行 dev 分支时出现的第三个不同错误(尽管实际上没有任何更改???)。 Master 分支在 Android 手机上运行良好。

Another error

编辑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);
});
}


}

最佳答案

好的,通过您的代码我们可以得到以下内容:

  • 对于第二个错误,可能是因为您尝试通过 window 对象访问插件,但其中不存在插件,因为没有可用的 cordova。

  • 我强烈建议您使用 ionic-native因为他们完成了包装插件的所有工作,因此我们可以更好、更简单地使用它们。

  • 如果可能的话,请务必在检查平台是 cordova、iOS 还是 Android 后调用您的插件,这样在不在模拟器上进行测试时就不会破坏您的应用程序(在生产/测试中您可以取消此检查,但对于生产来说最好这样做),因此请尝试在 if(this.platform.is('cordova')){} 中使用您的代码。

  • 您主页中的 co.event 错误只是因为您没有在主页中声明 event 变量,因此它无法识别 eventevent.month。因此,我建议检查您所有的主页绑定(bind)以及 .ts 变量和函数。

希望这有帮助。

关于javascript - 没有改变任何东西,突然收到 Ionic TypeError co.event is undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46000732/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com