本文介绍了在AngularJS之后(而不是之前)加载jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了让angular.element指向jQuery而不是jQLite,需要在页面头部的Angular之前加载jQuery.

In order to let angular.element point to jQuery instead of jQLite, one needs to load jQuery before Angular in the page head.

但是,出于性能原因(尤其是在移动设备上),如果可以在AngularJS加载后加载jQuery,那就太好了.jQuery库相对较大,因此让折叠内容之上"取决于jQuery lite,让jQuery在Angular之后异步加载,将会提高性能.

However, for performance reasons(especially on mobile devices) it would be nice if it was possible to load jQuery after AngularJS is loaded.The jQuery library is relatively large, so letting the 'above the fold content' depend on jQuery lite and let jQuery load asynchronously after Angular, would provide an increase in performance.

我认为Angular公开它的bindJquery函数和JQLitePrototype对象是可能的.

I think it would be possible if Angular would expose it's bindJquery function and it's JQLitePrototype object.

任何人都知道如何在不接触Angular核心的情况下执行此操作吗?

Anyone any ideas how to do this without touching the Angular core?

推荐答案

您可以在加载jQuery后手动扩展JQLite原型:

You can manually extend JQLite prototype after jQuery is loaded:

angular.extend(angular.element.prototype, jQuery.fn);

但是,由于这不是jQuery与Angular一起使用的设计,因此可能会带来不必要的问题.但是,如果您唯一的意图是使用一些有用的jQuery方法来扩展angular.element,那应该没问题.

However since this is not designed usage of jQuery with Angular it might bring unwanted problems. But if your only intention is to extend angular.element with some useful jQuery methods, this should be fine.

查看下面的演示,看看即使在Angular之后加载jQuery,在angular.element中如何使用jQuery的方法.

Check the demo below to see how jQuery's methods are available in angular.element even though jQuery is loaded after Angular.

这篇关于在AngularJS之后(而不是之前)加载jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 03:47