Reputation: 1227
Im using Event fucntion to publish some data in app. But its not working in ionic 4. I need to know ionic 4 support Events or not?
import { Events } from '@ionic-angular';
// Module not found: Error: Can't resolve '@ionic-angular'
Upvotes: 1
Views: 5692
Reputation: 46
Below solution is working in 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)
Upvotes: 1
Reputation: 31
You can use @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);
})
}
Upvotes: 3
Reputation: 719
The problem was in the version. When I updated to the latest patch of version 4, it was working.
npm i @ionic/[email protected]
Upvotes: 0