Should use jquery with angularjs ??

107 views
Skip to first unread message

biloki

unread,
Feb 4, 2014, 6:50:49 PM2/4/14
to ang...@googlegroups.com
Hi everyone,

I have a question very base: should we use jquery in the app that use angularjs ? If not, what should we use as the controller of DOM ?

Thank you very much

Johannes Zorn

unread,
Feb 5, 2014, 1:27:11 AM2/5/14
to ang...@googlegroups.com
Hi,

you certainly can, but it's not the angular way to do it. Let me quote the FAQ:

DOM Manipulation

Stop trying to use jQuery to modify the DOM in controllers. Really. That includes adding elements, removing elements, retrieving their contents, showing and hiding them. Use built-in directives, or write your own where necessary, to do your DOM manipulation. See below about duplicating functionality.

If you're struggling to break the habit, consider removing jQuery from your app. Really. Angular has the $http service and powerful directives that make it almost always unnecessary. Angular's bundled jQLite has a handful of the features most commonly used in writing Angular directives, especially binding to events.

Best,

Johannes 

calvin crane

unread,
Feb 5, 2014, 3:55:14 AM2/5/14
to ang...@googlegroups.com
No always you should try to NOT use any libs and frameworks wherever possible. Use just what you really need - if you had time then you should just use pure javascript with nothing else and write your own everything. This is seldom going to be the case and is a bit like asking ford to make their own tires and then again its not.

Johannes Zorn

unread,
Feb 5, 2014, 4:00:59 AM2/5/14
to ang...@googlegroups.com
I have to disagree here. In my opinion, wherever possible, use existing libraries. A community reviewed, well tested, often used library will provide code quality most developers can't reach. It is important to learn and try by yourself, but for a publicly accessible application I would strongly advise against using your own implementation of anything you can use from a library like jQuery. There might be exceptions, but by reading the initial question, I assume this is not one.

Best,

Johannes

calvin

unread,
Feb 5, 2014, 4:04:27 AM2/5/14
to ang...@googlegroups.com
You need to minimise dependencies – think about a simple javascript function that validates a form perhaps – you don’t need a lib. Agree that most people find Jquery a godsend. I was meaning more for ideology and that point was missed or poorly made by me. Dependencies are never a good thing but we like the advantages when it outweighs the weight of the framework or lib.

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/kxQAYzAsntI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Johannes Zorn

unread,
Feb 5, 2014, 4:08:19 AM2/5/14
to ang...@googlegroups.com
Again, I have to disagree. I'd rather have an additional 50k of libraries than a slow DOM traversal function, a buggy css selector engine or a malfunctioning trim-function that does not work well with UTF-8 characters.
It is nice to keep the dependencies small, but it's not the primary objective. Anyways, this begins to be off topic.

Best,

Johannes

calvin

unread,
Feb 5, 2014, 4:09:51 AM2/5/14
to ang...@googlegroups.com
I disagree too isn’t this fun. I do not assume that there will be poor code by the programmer like you. Its an ideology. And the best practise should be to start correctly.

Johannes Zorn

unread,
Feb 5, 2014, 4:13:13 AM2/5/14
to ang...@googlegroups.com
So why are you using Angular.js then?

calvin

unread,
Feb 5, 2014, 4:22:50 AM2/5/14
to ang...@googlegroups.com
I use Angular because it serves me and I don’t have to worry about the file size that it brings in my last demo. But I wouldn’t use it for a simple form verification if that is all that I am using. Angular comes with a lite weight version of something similar to Jquery as well and that should be used (and is used by Angular anyway) where possible if you have NG running.  For mobile apps it may be too much and also companies like vodaphone will want to use their own homegrown javascript engine which will use everything that is loaded.
Let me say that that I love frameworks as they allow far less than perfect programmers like me to get further and get some use from the toolset and drink more beer. It advances the evolution of code. I hope that speech recognition programming arrives sooner rather than later “give me an object that joins cars and manufactures tables and create a method to get me american cars for rent on date supplied” 

I want to see joe blogs able to do something more with code and in this sense I agree with you, that they obfuscate more complex patterns and constructs that we might mess up. And in this goal of getting more people 'coding' I guess I go away from a lot of programmers who love to complicate code with shorthand and over elegant solutions that are unreadable quickly. Those geeks would like to see this art kept dark. I like to get things working and less prone to break and that others can understand and therefore also help me.

Michael Hopper

unread,
Feb 5, 2014, 8:43:25 AM2/5/14
to ang...@googlegroups.com
AngularJS comes with a trimmed down version of jQuery (called jqLite) but you can use a full version if needed. The AngularJS way it to put your DOM manipulation code inside of AngularJS directives. Inside the directive code it is perfectly acceptable to use jQuery as the means of doing the DOM manipulation, it just needs to be wrapped inside a directive and follow the best practices for writing directives.

calvin

unread,
Feb 5, 2014, 8:47:25 AM2/5/14
to ang...@googlegroups.com
A core idea and goal with Angular is to avoid DOM manipulation where possible, but I can see that being difficult for some things. So for any part of the DOM that you want manipulated then you will assign a controller to control it.
Not thought about how if this works with adding DOM elements on the fly though in theory they ought to work fine. Still as Michael says it does come with jqLite and hopefully this can deal with what you need for after that I would say you can manage with plain js.

From: Michael Hopper <drm...@gmail.com>
Reply-To: <ang...@googlegroups.com>
Date: Wed, 5 Feb 2014 05:43:25 -0800 (PST)
To: <ang...@googlegroups.com>
Subject: [AngularJS] Re: Should use jquery with angularjs ??

--

Justin Russell

unread,
Feb 5, 2014, 9:01:10 AM2/5/14
to ang...@googlegroups.com
There is no incompatibility between jQuery and Angular, in fact Angular itself will make use of jQuery if it is available. See the docs for angular.element.

It's considered best practice to keep your DOM aware code within directives - though I don't think that's actually what OP was getting at when he says "controller". So I guess I'd say within your own application do whatever you think is best :) it really comes down to convenience vs bloat vs dependency control - and that's a decision you'll have to make. If you're publishing a module on the other hand... obviously staying within the framework becomes more desirable.


----------------------------------------------------------------


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages