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

220
Views
Angular2 Can I pass custom parameters to Host Listener event

Here is my current Host Listener

 @HostListener('document:myCustomEvent', ['$event'])
 updateNodes(event) {
    console.log(this.variable);
 }

And I'm calling it here:

var event = document.createEvent("CustomEvent");
event.initCustomEvent('myCustomEvent', true, true,
  true);

document.dispatchEvent(event);

My question is, can I pass my custom parameters to updateNodes ? For instance:

@HostListener('document:myCustomEvent', ['$event'])
updateNodes(event, param1, param2) {
 console.log(this.variable);
 console.log(param1);
 console.log(param2);
 }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Dispatch event this way:

var event = new CustomEvent(
    'myCustomEvent',
    { detail: { 'param1': 1, 'param2': 2 } }
);

document.dispatchEvent(event);

and then

@HostListener('document:myCustomEvent', ['$event', '$event.detail.param1', '$event.detail.param2'])
updateNodes(event, param1, param2) {
    console.log(param1);
    console.log(param2);
}

Plunker Example

about 4 years ago · Santiago Trujillo 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!