- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我没有太多信息,因为这是我遇到过的最奇怪的问题。
我正在用 Ionic 2 编写一个应用程序。昨晚我上床 sleep 时一切都很好。我今天早上起床继续工作,尽管加载了欢迎页面,但当您滚动到主页时,我收到一条错误,指出 co.event 未定义。
这是一个极其无用的错误消息的屏幕截图(为什么我不能在 Ionic 中从这个错误屏幕复制粘贴错误消息?太愚蠢了)。在我的代码库中搜索“co.event”返回 0 个结果。
我没有在任何地方更改任何一行代码。我什至不明白这是怎么可能的,更不用说如何解决它了。
我从我正在处理的分支切换到主分支,看看是否仍然可以。不,尽管对此进行了零更改,但仍存在完全不同的错误。
我可以通过进入 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 手机上运行良好。
编辑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
变量,因此它无法识别 event
和 event.month
。因此,我建议检查您所有的主页绑定(bind)以及 .ts 变量和函数。
希望这有帮助。
关于javascript - 没有改变任何东西,突然收到 Ionic TypeError co.event is undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46000732/
我想在聚焦时使用 ion-input 更改 ion-item 内的 ion-label 颜色。 我可以使用 --highlight-color-focused: yellow; 更改 ion-item
我想用 ionic 3 ion-list (或任何在 Ionic 3 中有效的东西)来显示水平列表而不是典型的垂直列表。 寻找解决方案 没有大量的 css 或难以维护的代码。
我目前使用 ionic 和我的 cordova 插件同时开发一个应用程序。我想知道如何使用文件 plugins/fetch.json 从本地文件系统更新我的插件。有什么想法吗? 最佳答案 使用 ion
当我在 ionic 项目文件夹中运行 ionic link 命令时,我收到以下错误消息 “除非您在 Ionic 项目文件夹中,否则您无法运行此命令” 我的系统信息。 Cordova CLI:6.3.1
如何注释 ion-row这样它就可以填满剩余的空间? 对于以下示例,黄色行“内容”应展开,直到占用所有剩余(绿色)空间。 Example text
我正在尝试构建一个 ionic 应用程序,但是当我运行 npm run ionic:build -–prod 时,出现以下错误: npm run ionic:build -–prod npm ERR!
我想在 ion-footer-bar 中添加两个按钮,如图片,但我的代码无法正常工作。 Button 333333333 Button
请有人澄清一下我什么时候会使用 ion-nav-view反对 ion-view ?我正在学习 AngularJS/Ionic(我对 AngularJS 有基本的了解;并且想使用 Ionic 来增强它)
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 1年前关闭。 Improve t
item-avatar 在我的项目中不起作用,它根本不显示 item-avatar 元素。 Recent Conversations
我正在使用带有属性interface="popover"的ion-select。弹出窗口在 select 下方打开,这使得弹出窗口非常小。 我发现,如果 ion-select 中有 10 个或更多项目
我创建了一个带有电容器的新项目 ionic。我使用 ionic 选择,但我有一个新的 ionic 选择选项,带有大文本,而不是在输入中分布。 Plaga/Enfermedad Al
如何像 ionic 中的许多应用程序一样滑动切换段?我在 ionic 官方文档中找不到任何 api。我只能找到this有用的线程。 但它似乎并不完美。有更好的解决办法吗? ionic 信息: Cord
我正在开发一个登录表单,所以在我的 中我有一个 (用作登录表单的容器)我想垂直居中。我用 css flexbox 和其他 css 技巧尝试了不同的方法,但对我没有任何作用!该卡片保留在页面顶部。你
我想在 ionic 选择(组合框)更改时隐藏和显示文本框 例如我有: ionic 选择中的 1 和 2如果我选择 1 文本框将隐藏,如果我选择 2 文本框将出现 这是我当前的代码: .ts onCha
我尝试在 ionic 4 中使用 ion-button 实现一个按钮,但没有样式输出,问题出在哪里,求助。 最佳答案 请使用以下代码 这里是 ionic v4 按钮的文档。 https://beta
我有一个在 ionic serve 中运行良好的应用程序。我现在正在尝试创建一个构建——这通常有效,但今天我遇到了问题。 ionic package build ios --profile devel
我正在使用 Ionic 2,在我的应用程序中我正在创建一个表单,如果出现验证错误,信息图标将出现在相关输入字段的右侧。 HTML如下,
我正在与一个远程团队一起开发 Ionic 1 应用程序,最近我们的版本彼此不喜欢。我想知道我是否也一直在从事 Ionic 2 项目,无论出于何种原因,我的 CLI “认为”这些应用程序也是 Ionic
我需要禁用默认 ion-ripple-effect在“ ionic 按钮”中。 我无法禁用 pointer-events因为我需要它。 PS:我引用了以下帖子,但找不到适合 Ionic 4
我是一名优秀的程序员,十分优秀!