简体   繁体   English

如何在我的应用程序中包含jQuery?

[英]How to include jQuery to my app?

I'm developing the app based on angular gulp generator . 我正在开发基于angular gulp generator的应用程序。 I want to use the angular-ui and bootstrap components. 我想使用angular-uibootstrap组件。 I am able to build the application, but generated index.html file contains script tags for boostrap, angular ui but jquery is missing here. 我能够构建该应用程序,但是生成的index.html文件包含boostrap,angular ui的script标签,但此处缺少jquery。

I have jquery in bower.js file and I ran bower install command. 我在bower.js文件中有jquery,并且运行了bower install命令。 It's installed in bower_components directory. 它安装在bower_components目录中。

Browser console contains the error 浏览器控制台包含错误

Error: Bootstrap's JavaScript requires jQuery
throw new Error('Bootstrap\'s JavaScript requires jQuery')

Is it neccessary inject query to angular app, or why does the error occur? 是否有必要将查询插入角度应用程序,或者为什么会发生错误?

From the FAQs : 常见问题解答

Does Angular use the jQuery library? Angular是否使用jQuery库?

Yes, Angular can use jQuery if it's present in your app when the application is being bootstrapped. 是的,如果在引导应用程序时Angular出现在您的应用程序中,则可以使用jQuery。 If jQuery is not present in your script path, Angular falls back to its own implementation of the subset of jQuery that we call jQLite. 如果您的脚本路径中不存在jQuery,则Angular会退回到它自己的jQuery子集(我们称为jQLite)的实现。

Angular 1.3 only supports jQuery 2.1 or above. Angular 1.3仅支持jQuery 2.1或更高版本。 jQuery 1.7 and newer might work correctly with Angular but we don't guarantee that. jQuery 1.7和更高版本可能可以与Angular一起正常使用,但我们不保证一定如此。

Use jQLite . 使用jQLite Guess that's your solution. 猜猜这就是您的解决方案。

The problem is that dear you are using Bootstrap js which require jquery. 问题是,亲爱的您正在使用需要jquery的Bootstrap js。

On Angular-ui website clearly said only required bootstrap css and anugular js. 在Angular-ui网站上明确表示仅需要引导CSS和Augular js。

The only required dependencies are: 唯一需要的依赖项是:

AngularJS (requires AngularJS 1.3.x, tested with 1.3.13). AngularJS(需要AngularJS 1.3.x,已通过1.3.13测试)。 0.12.0 is the last version of this library that supports AngularJS 1.2.x. 0.12.0是该库支持AngularJS 1.2.x的最新版本。

Bootstrap CSS (tested with version 3.1.1). Bootstrap CSS(经过3.1.1版测试)。 This version of the library (0.13.0) works only with Bootstrap CSS in version 3.x. 该版本的库(0.13.0)仅可用于3.x版的Bootstrap CSS。 0.8.0 is the last version of this library that supports Bootstrap CSS in version 2.3.x. 0.8.0是此库的最后一个版本,在2.3.x版中支持Bootstrap CSS。

So according to your question. 因此,根据您的问题。

Is it neccessary inject query to angular app, or why does the error occur? 是否有必要将查询插入角度应用程序,或者为什么会发生错误?

It is not necessary at all in the context of angular js. 在角度js的上下文中根本没有必要。

It is showing error because you are using boostrap js you have to add jquery before loading it. 它显示错误,因为您使用的是boostrap js,必须在加载jquery之前先添加它。 According to bootstrap. 根据引导程序。 Link 链接

Plugin dependencies Some plugins and CSS components depend on other plugins. 插件依赖性一些插件和CSS组件依赖于其他插件。 If you include plugins individually, make sure to check for these dependencies in the docs. 如果您单独包含插件,请确保在文档中检查这些依赖性。 Also note that all plugins depend on jQuery (this means jQuery must be included before the plugin files). 还要注意,所有插件都依赖jQuery(这意味着jQuery必须在插件文件之前包含jQuery)。 Consult our bower.json to see which versions of jQuery are supported. 请查阅我们的bower.json以查看支持哪些版本的jQuery。

By default angular used jqulite but if you add jquery before loading angular js it will use jquery. 默认情况下,angular使用jqulite,但是如果您在加载angular js之前添加jquery,它将使用jquery。

Hope it helps :). 希望能帮助到你 :)。

这应该可以解决您的问题bower install jqlite --save

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM