Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
angular javascript document and window functions best practice

In angular component.ts I use ngOnInit function to implement Javascript document and window functions.

for example :

ngOnInit(): void {
  document.addEventListener('mouseup', () => {
    this.isRatingPopupActive = false;
  });
}

this is part of my code to close opened popup after mouseup similar to facebook like button .. is this right?

and if it is wrong to use onInit this way, what is the best practice then?

thank you all <3

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In Angular, the common pattern to handle DOM events is using HostListener

Instead of using ngOnInit, declare the HostListener directive inside your class like this:

 @HostListener('window:mouseup', ['$event'])
 handleMouseUp(event){
   console.log("mouseup");
 }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!