间歇"展望了通过选择元素不被支持jqLit​​e&QUOT!;装载有RequireJS AngularJS时 [英] Intermittent "Looking up elements via selectors is not supported by jqLite!" when loading AngularJS with RequireJS

查看:370
本文介绍了间歇"展望了通过选择元素不被支持jqLit​​e&QUOT!;装载有RequireJS AngularJS时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过RequireJS加载AngularJS。 大多数时候是没有问题,但偶尔我得到的错误:

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

未捕获的错误:[jqLit​​e:nosel]!通过选择仰望元素不被支持jqLit​​e

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

我知道一切都是实际加载所以问题不在于与RequireJS没有找到这些文件。

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

下面是我的RequireJS配置:

Here is my RequireJS configuration:

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

下面是我如何加载RequireJS和kickstart的负载:

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>

我使用AngularJS 1.3.0和2.1.15 RequireJS

I'm using AngularJS 1.3.0 and RequireJS 2.1.15.

推荐答案

这样的间歇性问题通常是由于某一个缺失的依赖。大部分的时间以正确的顺序的模块负载,但是这只是由于机会。在一段时间后,运气不在你身边,你会得到意想不到的结果。

Intermittent problems like this are usually due to a missing dependency somewhere. Most of the time your modules load in the correct order but that's just due to chance. Once in a while, luck is not on your side and you get undesirable results.

问题是AngularJS使用jQuery只是可选的。如果是present,然后AngularJS使用它。如果它不存在,则AngularJS将使用一个jqLit​​e库,具有AngularJS捆绑,支持什么jQuery的可以做的一个子集。一个重要的区别是,像一个语句:

The issue is that AngularJS uses jQuery only optionally. If it is present, then AngularJS uses it. If it is absent, then AngularJS will use a jqLite library, bundled with AngularJS, that supports a subset of what jQuery can do. One important difference is that a statement like:

angular.element('[ng-controller="something"]')

只会工作,如果jQuery是提供给AngularJS,如果jqLit​​e来代替将无法工作。如果jQuery的前RequireJS负载AngularJS,那么AngularJS将不jQuery的工作,该语句将失败。

will work only if jQuery is available to AngularJS, and won't work if jqLite is used instead. If RequireJS loads AngularJS before jQuery, then AngularJS will be working without jQuery and the statement will fail.

可以通过更改AngularJS垫片是固定的:

 shim: {
   angular: {
       deps: ['jquery'],
       exports: "angular"
   },
 },

这篇关于间歇&QUOT;展望了通过选择元素不被支持jqLit​​e&QUOT!;装载有RequireJS AngularJS时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆