Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intermittent "Looking up elements via selectors is not supported by jqLite!" when loading AngularJS with RequireJS

I load AngularJS through RequireJS. Most of the time there is no problem but once in a while I get the error:

Uncaught Error: [jqLite:nosel] Looking up elements via selectors is not supported by jqLite!

I know that everything is actually loading so the issue is not with RequireJS not finding the files.

Here is my RequireJS configuration:

require.config({  baseUrl: 'lib/',  paths: {    jquery: 'external/jquery-2.1.1',    angular: 'external/angular',  },  shim: {    angular: {        exports: "angular"    },  }, }); 

Here is how I load RequireJS and kickstart the load:

<script type="text/javascript" src="lib/requirejs/require.js"></script> <script type="text/javascript" src="requirejs-config.js"></script> <script>   require(["start"]); </script> 

I'm using AngularJS 1.3.0 and RequireJS 2.1.15.

like image 501
Louis Avatar asked Nov 08 '14 15:11

Louis


1 Answers

If you do not want to depend on jQuery then, provided that you can enforce the browser version, instead of

angular.element('.mySelector'); 

use

angular.element(document.querySelector('.mySelector')); 

See here to find out which browsers support document.querySelector.

like image 64
ccpizza Avatar answered Oct 07 '22 02:10

ccpizza