ngx-application-event
v0.0.1
Published
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.3.2.
Readme
General Application Event Listener
This project was generated with Angular CLI version 13.3.2.
Usage
// define custom event types
class UserDeleted {}// publish event
@Component({...})
export class AppPublisher {
constructor(private applicationEventService: NgxApplicationEventService) {
}
publish(): void {
this.applicationEventService.publish(new UserDeleted())
}
}// listen event in Component
@Component({...})
export class AppListener {
@NgxEventListener
private on(event: UserDeleted) {
console.log(`New event: [${event.constructor.name}]`);
}
}// listen event in Service
@Service({...})
export class AppListener {
constructor(private applicationEventService: NgxApplicationEventService) {
}
publish(): void {
this.applicationEventService.publish(new UserDeleted())
}
listen(): void {
this.applicationEventService.listen(UserDeleted).subscribe(console.log)
}
}