publish(event, data)

This method allows you to fire events. Remember that our EventAggregator will be placed in some parent component, so you know which components will be subscribed to it. So, because of that, this method does not have a specific target; they are just events triggered to space and doesn't matter if they have zero or more subscribers.

The first argument is the event name. You can choose any name for this, as it is your custom event. It will be used as an identifier to call it from external components across our application. In this case, you can use EventAggregator to configure our loading bar, so it would be right to name our event according to it. We will call it dataRetrievingEvent.

The second argument is the data you want to pass to the event (to supply some data, for example) and it's completely optional. Most of the time, it will be an array or an object of data. You can even pass through a string value if you like. However, not all events need to receive new data.

We will call this method using our class definition variable for EventAggregator:

this.ea.publish('dataRetrievingEvent', {message: 'Loading...don't close the window!' 

That was very easy. We have our first custom event configured and ready to be called from any component in our application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.242.131