2

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?

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

2 Comments

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?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.