I want to add a script on head of index.html file and make that script work only on a button click

132 views Asked by At

I want to add a script on head of the index.html file and make that script work only on a button click from other component. How can i achieve this with Behaviour subject or can anyone suggest any other methods ?

I have added the code on the index file but the issue is the code is running before the button click, The code is working on the pageload

This is the code that i used on the index.html file, this code is now working during pageload but i want to make it work only on button click i've used a class .yes-button for the button :-

    const regArray = ['http://localhost:4200/registration/credentials'];
    const currentRoute = window.location.href;
    const isRegArray = regArray.indexOf(currentRoute);
    setTimeout(() => {
    if (isRegArray > -1) {
      debugger;
      document.querySelector('.yes-button')?.addEventListener('click', () => {
        console.log('cancel');
      });
    }
  }, 8000);
0

There are 0 answers