@leegee wrote:
Using the latest version of Ionic (3.9.2) on Windows 10, trying to use Events for the first time, I can’t get the code in the documentation to work.
import { Events } from 'ionic-angular'; // first page (publish an event when a user is created) constructor(public events: Events) {} createUser(user) { console.log('User created!') this.events.publish('user:created', user, Date.now()); } // second page (listen for the user created event after function is called) constructor(public events: Events) { events.subscribe('user:created', (user, time) => { // user and time are the same arguments passed in `events.publish(user, time)` console.log('Welcome', user, 'at', time); }); }
Error:
Uncaught (in promise): TypeError: Cannot read property 'subscribe' of undefined
What have I over-looked?
TIA
Lee
Posts: 1
Participants: 1