0.1.1 • Published 6 years ago

ngx-events v0.1.1

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

ngx-events

This library adds an Event property decorator and an EventListener method decorator.

You can add the Event property decorator to any angular EventEmitter and define it's name as a string.

@Event('someName') eventEmitter: EventEmitter<T> = new EventEmitter();

You can listen to this event by adding a method decorator called EventListener` with the event's name as parameter

 @EventListener('someName')
 someMethod(eventValue: T) {
   ...
 }

Whenever the annotated eventEmitter emits the annotated method will be called.

Example

class AppComponent {

@Event('eventName') buttonClicked: EventEmitter<string> = new EventEmitter();

  clicked() {
    this.buttonClicked.emit('clicked me');
  }
}

class SomeServiceOrComponent {
 
 @EventListener('eventName')
 listenToEventName(eventValue: string) {
   console.log('somewhere in the app the eventName eventEmitter emitted the following value', event);
 }
}