fromEvent

Creates an Observable that emits events of a specific type coming from the given event target. Creates an Observable from DOM events, or Node.js EventEmitter events or others.

@ViewChild('saveButton') saveButtom: ElementRef; 
// Here we make reference to the HTML button
<button #saveButton class="myButtom">
  Save information
</button>
ngAfterViewInit(): void {
  fromEvent(this.saveButtom.nativeElement, 'click')
    .pipe(
      exhaustMap(() => this.saveCourse(1, 'Hello')
      )
    ).subscribe();
}

Last updated