Event emitters can be injected into Directives. Event emitters take over
browser events with the same name. Emitted events do not bubble. Event
emitters can be injected even if there is no corresponding callback in
the template.
Use as follows:
@Decorator(...)
class MyDec(@EventEmitter('click') clickEmitter) {
...
fireClick() {
var eventData = {...};
this._clickEmitter(eventData);
}
}
15 lines
349 B
JavaScript
15 lines
349 B
JavaScript
import {CONST} from 'facade/lang';
|
|
import {DependencyAnnotation} from 'di/di';
|
|
|
|
/**
|
|
* The directive can inject an emitter function that would emit events onto the
|
|
* directive host element.
|
|
*/
|
|
export class EventEmitter extends DependencyAnnotation {
|
|
eventName: string;
|
|
@CONST()
|
|
constructor(eventName) {
|
|
this.eventName = eventName;
|
|
}
|
|
}
|