0

I am trying to change jquery code to javascript or typescript for working in angular 7 project. But i do know how to change it. If anyone know please help to find the solution?

$("#mytableId").find('table').each("tr").find("td:first").click(function(e){
    
    alert($(this).text());  //getting first td value of each tr
    
    
    });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<custom-table id="mytableId">
    <div>some content</div>
    <div>some content</div>
    <div>some content</div>
    <div> 
    <table>
    <thead>
    <th></th>
    </thead>
    <tbody>
    <tr>
    <td>123456</td>
    <td>Content</td>
    <td>Content</td>
    </tr>
    <tr>
    <td>189556</td>
    <td>Content</td>
    <td>Content</td>
    </tr>
    
    <tr>
    <td>122586</td>
    <td>Content</td>
    <td>Content</td>
    </tr>
    
    </tbody>
    </table>
    </div>
    
    </custom-table>

5
  • 2
    Angular and Jquery are fundamentally very different, I would suggest learning some basic angular before you'll be able to ask the right questions. There is no way to "convert" between the two. Commented Nov 26, 2019 at 15:01
  • @SpeedOfRound:Just i am asking How we can write same like that condition in angular 7? Commented Nov 26, 2019 at 15:04
  • @SpeedOfRound: Just tell me how to use viewchild and elementRef for that Or pure javascript Commented Nov 26, 2019 at 15:07
  • @SpeedOfRound: If you have same like this condition in your angular 7 project.. How you can manage it? Commented Nov 26, 2019 at 15:08
  • In Angular you use structural directives to build tables, you inject variables and handlers as you build the table rows. Commented Nov 26, 2019 at 15:14

1 Answer 1

1

You can use Angular event bindings to respond to any DOM event(click in your case). you can find the documentation here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.