Prevent AngularJs from using jQuery library

angularjs, jquery

Solution

UPDATE: Since v1.4.0-beta.6, Angular now has built-in support for choosing not to use jQuery (or use a specific version if multiple versions are loaded): ngJq

Unfortunately, there is no built-in way to disable jQuery (although it sounds like a very reasonable feature).

Two far from ideal solutions would be:

1.) Tyler's solution of modifying the Angular source.

2.) Since angular uses `window.jQuery` to look for...you guessed it...`jQuery` (and assuming you can control what script is run before and after angular.js), you could temporarily "hide" jQuery from Angular:

/* Run before angular.js */
if (window.jQuery) {
    window.hideJQuery = window.jQuery;
    window.jQuery = false;
}

// <script src="angular.js"></script>

if (window.hideJQuery) {
    window.jQuery = window.hideJQuery;
    window.hideJQuery = undefined;
}

Problem

Question: How can I prevent jQuery from being used by AngularJs? Background: I'm developing a standalone app in AngularJs that can be "inserted" in to already existing client websites. These client websites likely already use jQuery. If you've used AngularJs, you probably already know that it uses jqLite (a subset of jQuery). But if the jQuery library is loaded before an Angular app initialises then Angular will use that instead. There is no guarantee clients will load it after. Using jQuery instead of the jqLite library has caused other issues and I simply don't need jQuery. Is there a way to prevent AngularJs from using it and just stick to jqLite? Thanks EDIT 1: The issues I get when letting angular include and use jQuery are: "GET http://localhost.dev/angular/js/jquery-1.10.2.js?_=1401232704848 404 (Not Found)" "Uncaught SyntaxError: Unexpected token <" (error in jQuery v2.1.1 file, line 330) I'm testing with jQuery-2.1.1 so not even sure why it's looking for version 1.10.2 EDIT 2: I'm after a method that preferably does not require modifications to the core AngularJs file.

Original source

Related problems