Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I have built a site using AngularJS 1.2.9 which is being added into a client's website as a block in the body via a CMS. I have no control over the header of the page and they are using an old version of jQuery (1.6).

As Angular by default uses jQuery if it detects it is loaded in the DOM I am getting element not defined errors for the element references in the compile link functions etc.

I need to find a way of stopping Angular from using jQuery and instead just defaulting to using the default jqLite. A weird request I know but I don't have any control over the header scripts and the page is throwing errors for all the selector code. I found this in the AngularJS docs for 1.2

Angular 1.2 only operates with jQuery 1.7.1 or above.

So I assume this error is caused by the older 1.6 version of jQuery being loaded in.

So my question is:

Is there a way to manually tell AngularJS NOT to use jQuery during bootstrapping?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Not sure if this will work for you, but it has solved similar problems for me in the past.

<script>
  var backup = {
    $: window.$,
    jQuery: window.jQuery
  };
  delete $;
  delete jQuery;
</script>

<script src="path/to/Angular.js"></script>

<script>
  var $ = backup.$;
  var jQuery = backup.jQuery;
  delete backup;
</script>
share|improve this answer
    
Thanks TRGWII - will try it and let you know. Can you talk me through the 3rd script block? I assume it is saving a reference to jQuery and then deleting it in the first block then after loading angular adding it back again? If so - how do you know if angular has finished bootstrapping before reinstating it? – Tim Feb 6 at 16:21
    
I re-add the jquery to window in the end to prevent other stuff further down the page from breaking, in case it wasn't clear. – TRGWII Feb 6 at 16:22
    
OK - thanks. Just trying it out. – Tim Feb 6 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.