因为我遇到了一种奇怪的情况,即element
控制器的链接功能中的有角对象最终变成了jQLite对象,尽管jQuery确实存在,就像加载到内存中一样,并且可以在同一页的其他地方成功使用。
在这个问题上,Angular FAQ相当模糊:
是的,如果在启动应用程序时Angular可以在您的应用程序中使用jQuery,则可以使用jQuery。如果您的脚本路径中不存在jQuery,则Angular会退回到它自己的jQuery子集(我们称为jQLite)的实现。
那么“呈现”到底是什么意思?
如果首先包含Angular.js,它将使用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)时发生了此问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句