【发布时间】:2019-08-29 12:07:17
【问题描述】:
有没有人在 Ionic 3 中观察到发布事件时抛出异常?
编辑:经过仔细检查,异常与注入的Events 在构造函数首次调用后的某个时间变为undefined 有关。我想知道是否有我不知道的先决条件,例如为了注入Events,它必须在一个组件内完成吗?在我的情况下,我正在尝试从提供者发布事件:
import { Injectable } from '@angular/core';
import { Events } from 'ionic-angular';
...
@Injectable()
export class MyProvider {
...
constructor(public http: HttpClient,
private events: Events,
) {
console.log('Hello MyProvider Provider');
console.log(`${ this.events } ${ typeof this.events }`) // [object Object] object
...
private onUpdate(p: IAPProduct) {
console.log(`${ this.events } `) // undefined
this.events.publish('my event', p) // TypeError: undefined is not an object (evaluating 'this.events.publish')
}
唯一可能是一个因素的其他细节是 onUpdate 在其构造函数执行期间被用作回调。
提前感谢您的宝贵时间。
【问题讨论】:
标签: ionic3