AngularJS 真的需要 jQuery 吗? [英] Does AngularJS really need jQuery?

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

问题描述

我读到 AngularJS 带有 jQ​​uery 的精简版.然而,我一直听到有人谈论 Angular 和 jQuery 的结合.我什至查看了 ng-grid 并注意到它说:

I was reading that AngularJS comes with a lite version of jQuery. However I keep hearing reference to people who talk about Angular and jQuery going together. I even checked out ng-grid and noticed that it says:

AngularUI 团队用 AngularJS 和 jQuery 编写的 Angular 数据网格

Angular Data Grid written in AngularJS and jQuery by the AngularUI Team

因此,如果我确实使用 Angular,那么我什么时候需要 jQuery,而作为 AngularJS 一部分的版本没有提供什么?

So if I do use Angular just when would I need jQuery and what does the version that comes as part of AngularJS not provide?

推荐答案

jQLite 是一个非常精简的 jQuery 版本.jQLite 足以让 angular 工作.这是为了最小化依赖性.

jQLite is a very stripped-down version of jQuery. jQLite is enough for angular to work. This is to minimize dependencies.

然而,如果你在 angular 之前加载 jQuery ,那么 angular 将使用 jQuery.

Yet, if you load jQuery before angular, then angular will use jQuery.

大多数时候,您不需要使用 jQuery.即便如此,对于初学者来说,还是建议完全不使用 jQuery,因为当有一种简单/有角度的方法时会倾向于使用 jQuery.这方面的例子太多了(主要是在有 ngShowngHide 指令时通过 jQuery 显示和隐藏元素).

Most of the time, you do not need to use jQuery. Even so much that, for beginners, it is advised to leave out jQuery completely as there would be a tendency to use jQuery when there is an easy / angular way. There has been so many examples on this (mostly showing and hiding elements through jQuery when there are ngShow and ngHide directives).

稍后,当您开始编写指令时,您可能需要添加 jQuery.

Later on, when you start to write directives, you then may need to add jQuery.

ngGrid 可能会做很多 jqLit​​e 无法满足的事情.因此,他们使用了 jQuery.

ngGrid possibly does many things for which jqLite would not suffice. Thus, they used jQuery.

jqLit​​e 的文档和特性:http://docs.angularjs.org/api/angular.element

Documentation and features of jqLite: http://docs.angularjs.org/api/angular.element

这篇关于AngularJS 真的需要 jQuery 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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