Ionic 4 不支持事件?

Ionic 4 Not support Events?

正在使用事件函数在应用程序中发布一些数据。但它在 ionic 4 中不起作用。我需要知道 ionic 4 是否支持事件?

import { Events } from '@ionic-angular';
// Module not found: Error: Can't resolve '@ionic-angular'

以下解决方案适用于 ionic v4

import { Events } from '@ionic/angular';

constructor(private events: Events) {
    events.subscribe('notificationLength', notilen => {
    //TO DO`enter code here`
    })
}

// Publish the events where ever you want
this.events.publish('notificationLength', this.NotificationList.length)

版本问题。当我更新到版本4的最新补丁时,它正在工作。

npm i @ionic/angular@4.11.10 

您可以使用@angular/Events

//MyEvents Service Page

import { Injectable } from '@angular/core';
import { Subject, Observable } from 'rxjs';

@Injectable({
    providedIn: 'root'
})
export class EventsService {

    constructor() { }

    private subject = new Subject<any>();

    sendMessage(text){
    this.subject.next(text);
    }

    getMessage():Observable<any>{
    return this.subject.asObservable();
    }
}
//Page for sendMessage

constructor(private events: EventsService) {
    this.events.sendMessage({'created':1}); //send message key-value format
}
//Page for getMessage

subscription: Subscription;

constructor(private events: EventsService) { 
    this.subscription = this.events.getMessage().subscribe(text => {
        console.log(text.created);
    })
}