In this tutorial, we will learn about from event of RXJS.

Turn the event into an observable sequence

This operator will give output as an observable that is to be used on elements that emit events for example buttons, clicks, etc.

Parameters

target − The target is the dom element

eventName − eventName you want to capture for example click, mouseover, etc.

Return value

It returns an observable.

syntax:

fromEvent(target: eventtarget, eventName: string): Observable

Example:

<button #addBtn class="btn btn-primary">Add</button>

---------------------------
@ViewChild("addBtn", { static: false }) addBtn: ElementRef;

let count = 1;
fromEvent(this.addBtn.nativeElement, "click").subscribe((response) => {
  let countVal = count++;     
  console.log(countVal);
});

Output:
1,2,3,4,5.....

Topics covered:

Found this article helpful?

TutsCoder tutorials are free and ad-light — supported by readers like you. Buy me a coffee (or two ☕☕) as a token of appreciation and help keep Angular & Node.js content coming!

One-time. No subscription. 100% optional. 🙏 Every coffee counts!

Leave a Comment

Your email will not be published. Spam-free zone. ✌️

Available for Projects

Need Help With Your
Angular or Node.js Project?

7+ years of MEAN Stack experience. I build scalable Angular 21 apps, Node.js APIs, and SaaS products — delivered on time, every time.

7+ Years MEAN Stack Angular 21 + Nx Expert 20+ Projects Delivered Remote / Freelance