0

I have a function on the index.html file of my project, i want this function to work only on the button click. The button click is on the other component. How can i achieve this ?

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

this is the function this clarity is from Microsoft clarity.

  • you can use On your htm template file, if you function is in other component you should use @ViewChild to get a reference to that component and then use – dmance Nov 14 '22 at 06:26
  • What is stopping you from exporting this function and importing it into your component? It's not part of a component - or else the function keyword wouldn't be there. – Chris Hamilton Nov 14 '22 at 07:03

0 Answers0