angular如何确定jQuery是否存在
How does angular determine whether jQuery is present?
因为我遇到了一种奇怪的情况,即控制器链接函数中的角度对象(如element
)最终成为jQLite对象,尽管jQuery肯定存在于内存中,并在同一页面的其他地方成功使用。
Angular常见问题解答在这个问题上相当模糊:
是的,Angular可以在应用程序启动时使用jQuery。如果您的脚本路径中没有jQuery,Angular将返回到它自己的jQuery子集实现,我们称之为jQLite。
那么"present"到底是什么意思呢?
Angular.js如果首先包含jQuery,就会使用jQuery,否则就会使用自己的jqLite。如果在AngularJS之后加载jQuery,AngularJS会将自己附加到jqLite,但您仍然可以通过$访问jQuery。
请参阅下面angular.js用于确定是否加载jquery的代码:
// bind to jQuery if present;
jQuery = window.jQuery;
// Use jQuery if it exists with proper functionality, otherwise default to us.
// Angular 1.2+ requires jQuery 1.7+ for on()/off() support.
// Angular 1.3+ technically requires at least jQuery 2.1+ but it may work with older
// versions. It will not work for sure with jQuery <1.7, though.
if (jQuery && jQuery.fn.on) {
jqLite = jQuery;
extend(jQuery.fn, {
scope: JQLitePrototype.scope,
isolateScope: JQLitePrototype.isolateScope,
controller: JQLitePrototype.controller,
injector: JQLitePrototype.injector,
inheritedData: JQLitePrototype.inheritedData
});
更改脚本标记的顺序可能不会经常发生,但如果您开始对代码库进行模块化,则可能会发生这种情况。特别是,在使用一些模块加载程序(如RequireJS)时出现了此问题。
相关文章:
- 用于检查数组中是否存在元素的javascript自定义方法
- 是否存在React Native“;WEB代码安全防护”;
- 验证会话中是否存在对象's数组
- 如何查找值是否存在于二叉树中
- 检查是否存在使用chrome扩展的javascript库
- 是否存在Javascript Liferay Service库的文档?如何处理错误情况
- 测试mongo脚本中是否存在参数
- 检查搜索结果是否存在多次如果是,则在Javascript中只显示一个结果
- 检查数组中是否存在字符串值,并返回找到的数组值js
- 如何通过json对象选项卡中的Id来检查对象是否存在
- 检查是否存在任意控制器/操作
- Javascript滑块不滑动,如何判断是否存在JS冲突
- 根据手机上是否存在文件,在jQuery mobile中动态填充列表视图
- javascript测试是否存在两个标志中的任何一个
- 如何使用javascript检查移动sd卡中是否存在文件
- 当提供函数名称时,检查函数是否存在于同一作用域中
- 需要帮助使用JQuery.inArray()检查值是否存在
- 确定元素是否存在
- 使用javascript检查服务器上是否存在html文件
- 是否存在类似ExtJS 4的框架;正常的“;网站