What are the main differences between jQuery and Angularjs?

Asked

Viewed 42,074 times

83

I am noticing the adhesion of Angularjs and the abandonment of jQuery by some developers, however I do not know the advantages of Angularjs because I have never worked with this framework.

Since some blogs (ex: jeremyzerr, paulhammant) encourage the use of Angularjs, I would like to know what the differences between these frameworks, and if it’s worth the exchange.

Some topics:

  • Everything that is done in jQuery can be done in Angularjs?
  • Which uses the least code?
  • Which is the fastest in processing?
  • Which the lighter?
  • Which is the easiest maintenance?
  • How is the learning curve for each one?
  • What are the limitations of each?
  • What one does better than the other?
  • It is legal to use both at the same time?

Note: examples are welcome

  • 5

    I don’t know if you can compare them directly, they are completely different things. Angular is a framework, and jQuery is not. They are usually placed on opposite sides because the purpose of jQuery is to manipulate the DOM, while in Angular views are considered static, one does not manipulate the DOM in the same way as with jQuery.

  • @bfavaretto I never worked with AngularJS, but what little I’ve seen it acts on HTML just as it is possible to do with JQuery. So this doubt arose about the differences between the two in practice.

  • 2

    I also know little about Angular, but from what I understand it works with views that are entirely replaced when needed (a view can be an element or several). With jQuery it is more common to manipulate individual elements. I was hoping someone would reply or ask to clarify. I have doubts about this closure, I don’t think Gorilla vs. Shark; maybe whale versus dolphin :)

  • 1

    "I’m noticing (...) by some developers" "Since some blogs encourage..." [Citation needed] :P (in other words, please link to examples if possible, as this may help to create the context necessary for this question to be answered objectively; I voted for reopening anyway, but feel that without this context the answers can ramble a lot, use different points of view, etc)

  • 1

    @mgibsonbr edited the question and added 2 blogs for reference, both address some points about Angularjs quoting jQuery.

  • You even studied the plunker that jeremyzerr did? jQuery vs. Angularjs

  • I think the angular difference for jQuery is something similar to the difference between pure PHP and a framework with not very large learning curve, one cannot expect Angular to be faster than Jquery since angular is a framework while jQuery is a JS library. I did not study angular due to lack of time, but it is worth the little I saw about it, it is worth a lot, has a very small learning curve, its use is simple, maintenance also has a great performance...

  • Just to leave my two cents here, jQuery is rather a framework. From specific field, but a framework.

  • @Brunoaugusto would not be a library no? Look here

  • Often, a library and a specific domain framework end up being the same thing. The biggest difference between one and the other is all the methodology. Ah! Soon I bring your trophy gold shovel :p

Show 5 more comments

4 answers

70


Basically, jQuery is a Javascript library, which simplifies o Javascript for common activities in day-to-day development. Excellent for handling the GIFT with much less code than pure JS.

Example of jQuery:
Selecting the <div id="meudiv"></div>
Javascript:  document.getElementByID('meudiv')
jQuery:        $('#meudiv')

Angularjs is already a framework, that works with data, focusing on <-> application user interaction. It has the following main points:

  • Double Hand Data Binding. Example.
    You define a type of data (called Model) and any changes to it occur throughout the application, where they appear.
  • Development pattern [MVVM] (similar to the MVC).
  • Integrated template engine
    Ex.: You receive an object from a server JSON with several items and assigns them to a Model called Pessoas at Angular. This is our object that we attach to the model through an Angular controller:

    pessoas = [
            {nome: 'Romulo', sobrenome: 'Zoch', caracteristica: 'Lindo'},
            {nome: 'João', sobrenome: 'Do caminhão', caracteristica: 'feio'}
    ]
    

To list all items of the/model object, you can, for example, do the following:

<li ng-repeat="pessoa in pessoas" ng-model="pessoas">
    {{pessoa.nome}} é {{pessoa.caracteristica}} e seu sobrenome é
    {{pessoa.sobrenome}}
</li>


And Angularjs will display the following:

  • Romulo is beautiful and his last name is Zoch
  • John is ugly and his last name is From the truck
  • Directorates customizadas (as reusable components, custom html creation).
    You can, for example, create an element <meubotao>texto</meubotao>, which will render a full snippet that you set, "make it count": <button class="meubotao" rel="meubtn" onclick="funcaoPadrao()">texto</button>
  • Ready to work with API’s REST (which normally deliver the content in JSON)
  • Client-side form validation
  • Communication with the server
  • Localization Ready (ready p/ multi-language translation)
  • Addiction injection (it’s not really a Feature, but it’s a difference from jQuery, which doesn’t have it)
  • TDD (Development aimed at testing)

Note: It is worth remembering that Angularjs USA jQuery itself. It comes with a Lite version of jQuery integrated. You can even use jQuery inside the Angular ( Although it is not indicated to change the GIFT via jQuery within an Angular application, as this should be done via custom directives).

Some really cool information on each one you can find on Wikipedia. The information is very simple and general: Angular and jQuery

  • Your answer talks a lot, but at the same time does not speak anything. It seems to me that the only difference between them is that to run Jquery I need the tag <script> and Angularjs don’t. So far I haven’t found anything that justifies dedicating my energy and time to reinventing the wheel. This is a particular opinion, I expected to find a topic telling me: It’s better because {a}, {b}, {c}.

  • 8

    I think you really don’t understand anything. Angular JS is for one thing, jQuery for another

  • 4

    @Marcelobarbosa "Basically, jQuery is a Javascript library, which simplifies Javascript" and "Já Angularjs is a framework, which works with data, focusing on user interaction <-> application. "

  • That is, I can use both together, it is not an option "This" or "That". It is that the templates, examples and tutorials are very relative, very simple, and I only see actions that I do in the same way using Jquery. Currently I work with a clean HTML, with Divs and their respective Id’s. Jquery loads the objects via ajax and Gero the required HTML from Js. Putting tags in the middle of html code, at first, gives me the feeling of dirty code. I’m rewriting some things with Angular. I appreciate the response and dedication.

  • Development Standard, MVW Model-View-Whatever ;)

  • 1

    Excellent answer, but oddly enough the link you mentioned speaks of library and framework are pretty much the same thing. The jquery itself is called the framework. The problem today is that people (I’m not talking about you) have confused "applications" or "design Patterns" with framework, an example is IC, cakephp and Laravel. In fact they are frameworks-based web applications (so much so that cake and Laravel separate the framework). Just a hint ;)

Show 1 more comment

12

As regards differences in implementation of Angular vs. Jquery

Angular.js is a framework. When running Angular.js, it is loaded, where its DOM and Javascript tree is transformed into an angular application. This is because HTML code with special characters (directives and angular filters) is compiled and angular performs a binding between Controller, Model and View (MVC standard). So you need to understand these controllers, services, directives, etc. I understand it’s a moderate learning curve. It would be a good option for an application that has CRUD for example.

Just include the property ng-app in the html element we want to "activate" the Angularjs:

<html ng-app>
<head>
     <title>Lista de compras</title>
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js"></script>
 </head>
 <body>
    Hello <input type="text" ng-model="yourName"/>
    <h1>Hello {{yourName}}</h1>
 </body>
</html>

Beyond the property ng-app (line 1), we use for Databind the property ng-model, to inform that this element will be connected to an Angularjs variable, through the yourName variable on line 8. This means that any change in the text box will update the variable value.

Every time the template is updated - either through asynchronous AJAX calling, or through direct manipulation somewhere in the Controller code, Angular updates the data model and keeps it in sync with the View.

Among Objectives/ Characteristics:

  • Abstract DOM manipulation from application logic. This improves code testing.
  • Abstract the coupling between the client side and the server side of the application. This allows application development to evolve on both sides in parallel and allows code reuse.
  • Guide developers through the construction of the entire application: from the design of Interface, through the writing of business rules, to the testing of the application.

Jquery is a library javascript for DOM manipulation (e.g. changing colors of an element, onclick events, animation, etc...). When running Jquery, your code will call functions from a library, prompted by some DOM event for example.

Already to load the Jquery we insert the reference to the library: <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.js">

Then we insert a jQuery function on the page so that when the page is ready we can use Jquery:

$(function() { // Quando a página estiver carregada
    RealizarAlgo();
})

Among Objectives/ Characteristics:

  • Resolving the incompatibility between browsers.
  • Code reduction with code reuse through plugins created by other developers.
  • Works with AJAX.
  • Secure deployment of CSS resources.

As regards the use, found this link http://w3techs.com/technologies/comparison/js-angularjs,js-jquery

  • Excellent answer, I only disagree with this part about framework != library, a framework nothing more than a large library, in the end result basically both are frameworks. The jquery itself is called the framework. The problem today is that people (I’m not talking about you) have confused "applications" or "design Patterns" with framework, an example is IC, cakephp and Laravel. In fact they are frameworks-based web applications (so much so that cake and Laravel separate the framework). Just a hint ;)

10

Jquery is simply an API for easy handling of the DOM (Document Object Model)

Angularjs is a complete MVC Framework with support for Data Binding, Dependency Injection, Custom HTML Element Creation (Directives), Module Loading with Dependency Management, Routing and History Management, Services, Promises, etc. In other words, it allows the creation of a complete application in a robust and organized way, writing much more expressive code and easy to maintain. It is another paradigm and to be used efficiently you must study and understand these new concepts cited.

OBS: Angular itself uses Jquery but you can make an entire application without using a single Jquery command because in the Angular approach you use other features provided by the Framework that are more productive. When using Angular try not to use Jquery directly, for example, instead of adding an event handler click via Function .on(…) use ng-click.

6

In my view it is not possible to compare the 2, they are different proposals, although they have some similar implementations as:

The 2 have access to data by Ajax
The 2 modify the DOM at runtime (like show and hide objects/ create or destroy objects)
Jquery can even complement Angular (although not recommended).

Ideal is you learn the 2, start with Jquery which is simpler and then go to Angular.

You should keep in mind that the basis of the 2 is Javascript, I advise knowing very well the javascript language.

For example: I started with Jquery even before I knew javascript well and as I passed the time I discovered that many times I didn’t even need to use Jquery to reach my goal.

Good studies.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.