O'Reilly logo

Hands-On Full Stack Web Development with Aurelia by Erikson Haziz Murrugarra Sifuentes, Diego Jose Arguelles Rojas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

subscribe(event, callbackFunction)

If we published an event at the first method, now it's time to listen to it. The first parameter is the event name we want to subscribe, and the second is a callback function that can be used to get the value sent by the event publisher. This data can be a simple string, or, like in our case, an object.

Like the preceding example, we can access this method through our EventAggregator class instance in our component:

let subscription = this.ea.subscribe('dataRetrievingEvent', response => {
    console.log(response);
    // This should yield: Object {message: "Loading...don't close the window!"}
});

We have defined a subscriber object which is basically a method call. This object will make a direct reference to the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required