Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to integrate jQuery plugins in AngularJS

People also ask

Can we use jQuery plugin in Angular?

You should not use jQuery in Angular. While it is possible (see other answers for this question), it is discouraged. Why? Angular holds an own representation of the DOM in its memory and doesn't use query-selectors (functions like document.

Can we use jQuery and AngularJS together?

You can use JQuery together with AngularJS. AngularJS also have a lightweight version JQLite which contains all the JQuery functionality the AngularJS project needs.


Yes, you are correct. If you are using a jQuery plugin, do not put the code in the controller. Instead create a directive and put the code that you would normally have inside the link function of the directive.

There are a couple of points in the documentation that you could take a look at. You can find them here:
Common Pitfalls

Using controllers correctly

Ensure that when you are referencing the script in your view, you refer it last - after the angularjs library, controllers, services and filters are referenced.

EDIT: Rather than using $(element), you can make use of angular.element(element) when using AngularJS with jQuery