emit event angular code example

Example 1: output events in angular with asynchronous

content_copy
      
      <zippy (open)="onOpen($event)" (close)="onClose($event)"></zippy>

Example 2: angular event emitter

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


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

Example 3: send event to child component angular

Parent-Component

eventsSubject: Subject<void> = new Subject<void>();

emitEventToChild() {
  this.eventsSubject.next();
}


Parent-HTML

<child [events]="eventsSubject.asObservable()"> </child>


Child-Component

private eventsSubscription: Subscription;

@Input() events: Observable<void>;

ngOnInit(){
  this.eventsSubscription = this.events.subscribe(() => doSomething());
}

ngOnDestroy() {
  this.eventsSubscription.unsubscribe();
}

Example 4: emitter angular

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