Using jquery in Angular2

Source: Internet
Author: User

I know Angular2 's idea of using jquery might see a little bit of an odd lot of you, and we all know that ANGULAR2 is responsible for managing everything related to our view components and DOM elements, which sounds like a good idea, and a working corner made with another frame can be easily done.

In other words, why would anyone want jquery and ANGULAR2 integration?

Well, there are cases where we still have to use jquery, like reusing some jquery code or component, it's impossible to rewrite everything with angular2, which is probably why you're reading this tutorial.

Now let's see how to do this, in fact it's really simple, basically all you have to do is add jquery script to your index.html and component declaration jquery, here's an example:

Import {Component} from 'Angular2/core'; declarevarJquery:any; @Component ({selector:'My-app', Template: '<button onclick="console.log (' It worked!! ')">JQuery Integration Test</button>              `}) ExportclassAppComponent {ngafterviewinit () {JQuery ('Button'). Click (); }}

When you run your application, you will see the text of it working! "On your console. That's what happened! This is a very short tutorial, but I hope it will help you.

Using jquery in Angular2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.