$emit() code example

Example 1: angular event emitter

@Output() open: EventEmitter<any> = new EventEmitter();


  toggel() {
  	this.open.emit(null);
  }

Example 2: event module in node js

const myEmitter = new MyEmitter();
let m = 0;
myEmitter.on('event', () => {
  console.log(++m);
});
myEmitter.emit('event');
// Prints: 1
myEmitter.emit('event');
// Prints: 2

Example 3: emitter angular

<component
  (open)="open($event)"
></component>

Example 4: eventemitter nodejs

myEmitter.on('status', (code, msg)=> console.log(`Got ${code} and ${msg}`));

Tags: