Event Aggregator
Use Aurelia's Event Aggregator for lightweight pub/sub communication between components.
Basic Usage
Injecting and Subscribing
import { ICustomElementViewModel, IEventAggregator, resolve } from 'aurelia';
export class MyComponent implements ICustomElementViewModel {
readonly ea: IEventAggregator = resolve(IEventAggregator);
bound() {
this.ea.subscribe('event-name', payload => {
// Handle the event payload
});
}
}Publishing Events
Strongly typed events
One-time subscriptions
Disposing of Subscriptions
Advanced Scenarios for Cross-Component Communication
Use Case #1: Parent/Child Communication
Child Component (Publishing an Event)
Parent Component (Subscribing to the Event)
Use Case #2: Plugin with Internal Communication
Plugin Component (Internal Communication)
Service (Triggering the Event)
Use Case #3: Plugin with Both Internal and Global Communication
Use Case #4: Extending the Event Aggregator
Extended Event Aggregator Implementation
Using the Extended Event Aggregator
Next steps
Last updated
Was this helpful?