Angular 6 trigger click event like jQuery

Discussão em 'Angular' iniciado por Raja, Setembro 12, 2024.

  1. Raja

    Raja Guest

    I have been using Angular 6 and I am new to the Angular environment too.

    My problem is that I have been thinking about this in a jQuery way.

    I want to trigger an anchor link on page load like the below jQuery code in Angular 6.

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
    $(document).ready(function () {
    $('#hello').click(function () {
    console.log('yo yo yo .....you good to go.!!!');
    });
    $('a').trigger('click');
    });
    </script>

    <a id="hello" href="http://www.google.com">Click me</a>


    How to achieve this in Angular 6? I know that we can add a click on the elements. But in my project, I don't know have a control on anchor tag. I mean I cannot add click method, instead I want to trigger it externally like jQuery.

    Continue reading...

Compartilhe esta Página