virender
virender

Reputation: 4647

Which is the right way to add Jquery and Angularjs in one project

I am starting to add Jquery and AngularJs in our next project. I seen some article say use Jquery before AngularJs and Some article used Jquery after AngularJs. so, I am little confuse about which one is right.

see KendoUI used jquery before AngularJs and their own library after it.

<script src="jquery.min.js"></script>
<script src="angular.min.js"></script>
<script src="kendo.all.min.js"></script>

What is the concept behind use jquery before AngularJs and Kendo or other library after AngularJs.

And why kendoUI will not work if we use it before AngularJs, what is the concept behind it.

Upvotes: 1

Views: 3427

Answers (2)

aa333
aa333

Reputation: 2576

Angular can work with or without jQuery. If loaded without jQuery already loaded, it'll use jQLite which only has a handful of jQuery functions. Reference

So if you plan to use jQuery in your JS it makes sense to load it before Angular which will prevent jQLite from being loaded at all.

Kendo UI includes Angular directives, which won't work correctly unless the Angular framework is loaded before it.

The same principle would apply to any library that uses the Angular framework. If a library does not use it then the load order has no effect.

Upvotes: 3

squiroid
squiroid

Reputation: 14037

If you load jQuery after AngularJS, AngularJS attaches itself to jqLite but you can still access jQuery through $. This is not a good situation to be in. If you are going to use jQuery then you should always load it before AngularJS.

Upvotes: 2

Related Questions