javascript pass parameter to event listener addeventlistener with arguments in angular 8 event listener function called parameters

The solution for “javascript pass parameter to event listener addeventlistener with arguments in angular 8 event listener function called parameters” can be found here. The following code will assist you in solving the problem.

var someEventHander=function(){
console.log(event,param1,param2);
}
//add listener
document.getElementById(“someid”).addEventListener(‘click’,someEventHander.bind(event,param1,param2)); // Import ElementRef,AfterViewInit from angular core

//Constructor
constructor(private elementRef: ElementRef) {}

ngAfterViewInit() {
const navbarToggler =
this.elementRef.nativeElement.querySelector(‘element’);
navbarToggler.addEventListener(‘click’, () => {
navbarToggler.classList.toggle(‘class’);
});
}var someEventHander=function(event,param1,param2){
console.log(event,param1,param2);
}
//add listener
document.getElementById(“someid”).addEventListener(‘click’,someEventHander.bind(event,’param1′,’param2′), false);

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in