prevent使用jQuery库AngularJs [英] Prevent AngularJs from using jQuery library

查看:100
本文介绍了prevent使用jQuery库AngularJs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

:如何从正在使用的AngularJs prevent的jQuery

Question: How can I prevent jQuery from being used by AngularJs?

背景

我在开发一个AngularJs独立的应用程序,可以插在已经存在的客户网站。

I'm developing a standalone app in AngularJs that can be "inserted" in to already existing client websites.

这些客户端的网站可能已经使用jQuery。

These client websites likely already use jQuery.

如果你使用AngularJs,你可能已经知道它使用jqLit​​e(jQuery的一个子集)。但是,如果jQuery库是角应用程序初始化之前加载,然后角度将使用该来代替。谁也不能保证客户端将后加载它。

If you've used AngularJs, you probably already know that it uses jqLite (a subset of jQuery). But if the jQuery library is loaded before an Angular app initialises then Angular will use that instead. There is no guarantee clients will load it after.

使用jQuery,而不是jqLit​​e库已经引起其他的问题,我根本就没有的需求的jQuery的。

Using jQuery instead of the jqLite library has caused other issues and I simply don't need jQuery.

有没有办法来prevent AngularJs使用它,只是坚持jqLit​​e?

Is there a way to prevent AngularJs from using it and just stick to jqLite?

感谢

修改1

让角时,我得到的问题包括与使用jQuery是:

The issues I get when letting angular include and use jQuery are:


  1. GET http://localhost.dev /angular/js/jquery-1.10.2.js?_=1401232704848 404(未找到)

未捕获的SyntaxError:意外的令牌LT;的(错误的jQuery 2.1.1文件,行330)

"Uncaught SyntaxError: Unexpected token <" (error in jQuery v2.1.1 file, line 330)

我与jQuery的测试-2.1.1因此,即使不知道为什么它寻找1.10.2版本

I'm testing with jQuery-2.1.1 so not even sure why it's looking for version 1.10.2

编辑2

这pferably $ P $的方法后,我的需要修改的核心AngularJs文件。

I'm after a method that preferably does not require modifications to the core AngularJs file.

推荐答案

更新:结果
由于V1.4.0-beta.6,角现在已经内置支持,选择不使用jQuery(或使用特定的版本,如果多个版本加载): ngJq

UPDATE:
Since v1.4.0-beta.6, Angular now has built-in support for choosing not to use jQuery (or use a specific version if multiple versions are loaded): ngJq

不幸的是,禁用jQuery的(虽然这听起来像一个非常合理的功能)没有内置的方式。

Unfortunately, there is no built-in way to disable jQuery (although it sounds like a very reasonable feature).

两个很不理想的解决方案将是:

Two far from ideal solutions would be:

1)修改角源泰勒的解决方案。

1.) Tyler's solution of modifying the Angular source.

2)由于角度使用 window.jQuery 寻找......你猜对了... 的jQuery (假设你可以控制脚本angular.js之前和之后运行),可以暂时从角隐藏jQuery的:

2.) Since angular uses window.jQuery to look for...you guessed it...jQuery (and assuming you can control what script is run before and after angular.js), you could temporarily "hide" jQuery from Angular:

/* Run before angular.js */
if (window.jQuery) {
    window.hideJQuery = window.jQuery;
    window.jQuery = false;
}

// <script src="angular.js"></script>

if (window.hideJQuery) {
    window.jQuery = window.hideJQuery;
    window.hideJQuery = undefined;
}

这篇关于prevent使用jQuery库AngularJs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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