I have a dynamic page where I need to click on a button. I tried the code below, but it is not working and not showing any alert. However, if we use the same code in the browser console, it executes and shows an alert. Can someone please suggest how to resolve this issue?
ngAfterViewInit(): void {
document.querySelector('.test-class')?.addEventListener('click', event => {
alert(event);
});
}