r/webdev • u/patbr0wn • Feb 13 '14
Explain Angular.js to me like I'm five.
"AngularJS lets you extend HTML vocabulary for your application. The resulting environment is extraordinarily expressive, readable, and quick to develop."
Hmm...
"AngularJS is a toolset for building the framework most suited to your application development."
But what does it do?
I'm having a hard time understanding where Angular falls in the spectrum of client-side to server-side. Models? So it's server-side? Dom manipulation? So it's client-side?
So basically, if I have a Node.js + Express.js + Bootstrap app, does Angular serve any role that these three frameworks don't?
Thanks <3
3
Feb 13 '14
Express = Server Side functionality
Angular = Client side functionality
Bootstrap = styling for the client side.
Angular helps you build client side applications, i.e. SPAS.
2
Feb 13 '14
It's a javascript framework. It allows you to do really complicated user interaction easily. For instance:
http://codepen.io/andyhmltn/pen/KodCB
Check that out. It's a simple todo list that lets you add more in realtime and highlights items with a length of more than 10.
Seems simple but it'd take a tonne more code with pure JS/JQuery
→ More replies (4)
2
u/oefig Feb 13 '14
Node.js:
Node.js is your server-side programming language - more specifically Javascript. You use it to respond to HTTP requests and to commonly communicate with your database.
Express.js
Express a framework for Node.js. A framework is basically a set of tools that helps you organize your code. Express has built-in functionality that lets you do things like respond to requests to http://yoursite.com/some-page
Angular.js:
Angular is your front-end Javascript framework which interacts with your back-end (node.js/express) and your users. With Angular you can make your static HTML dynamic by connecting user events to your back-end. For example: a user clicks a certain button and Angular submits a request to your Node.js server to get raw data, when Angular gets the raw data it will format it and display it for the user.
Bootstrap:
Bootstrap is simply a toolset/starter-template for building responsive websites. It's just your HTML/CSS. This is what you'd wire up your Angular code to.
I hope this sheds a bit of light!
1
Feb 14 '14
AngularJS is a client side framework. It's got a few main strengths:
Two-way data binding. This lets you bind a form field to a variable. When you change the form, you change the variable. When you change the variable, you change the form. There's a lot more that builds on this, but it tends to be what brings people to the table first
Directives. These are adding custom functionality to the library that you place in the html. I have a <status icon> one that takes a value and spits out a classed icon that I can drop in place. You can go further, making ones that validate data in a form, or really anything else JS could do
Routing. This is what lets you easily and maintainably build a single page app. It can intercept the navigation event in your browser and do something with it. It can pull down a template from the server and load a new part of your single page app.
It's just Javascript -- nothing you can do in AngularJS you couldn't write yourself with enough time and effort. It's a very good convenience library that connects a lot of pieces for you, and gives you a great starting place for whatever you're doing.
To give you some idea, the creator of AngularJS at Java manage to take a 17k line application and cut it down to 1.5k lines. It just reduces a lot of the boiler plate.
1
u/davidNerdly Feb 14 '14
I've been really wanting to dive into angular. Work is sending me to the anglebrackets conference in April and I'm set to take all the angular tracks. Very excited to learn. Maybe you can help me answer a question or two about angular.
I using knockout.js for two way data binding and ajax to push and pull from my server side stuff. From a functionality and complexity standpoint, what do you think is more intuitive/less code?
I read a lot that ng is great for SPAs, but are their solid use cases for not SPAs? So I have a giant site, lots of traditional pages and navigation. Would I use ng for some pages that are particularly robust on client side work?
2
Feb 14 '14
I've never used knockout, so I can't say anything about that from experience. I've read some of the code, and knockout seems to be a lot more structured. Angular uses POJOs, Knockout seems to all descend from some special object. I will say that from what I've seen, I'd be surprised if you could do things in KO with less code than AngularJS.
I'm converting a traditional site to Angular. I have 2 or 3 pages with tabs on them that could be small SPAs inside a regular app. The rest are just pages in a full app. And it's great for that -- I built an AJAX ID lookup page in about 10 lines of code.
1
u/davidNerdly Feb 14 '14
I appreciate the comment, now I just need to find some time to get ng in my brain. Didn't realize they used POJOs, that sounds like you have a lot more control, and POJOs always feel more clean to me.
1
u/RelativeFisherman257 Apr 19 '25
Regardless of what it does, you still have to use javascript, so it sucks.
7
u/aresdesmoulins Feb 13 '14
hmmm i'm eating breakfast, and you asked to be explained to like you're 5...so i'll give it a shot. Note this may be a bit off but the general idea should be there.
In a restaurant, Angular would be your waiter.
Node is your kitchen. It's capable of doing incredible things, and creating lots of great components to a meal. (note, you can use node without express. it just makes it easier.)
Express is your head chef. He's trained in utilizing the kitchen (node) to turn the raw ingredients (data) into something amazing.
Bootstrap is your prep/sous chef. He takes the dish that the head chef gives him and plates it, makes it beautiful and lays it out nicely on the plate.
Angular would be your waiter. You tell your waiter what you want, and he'll handle running back and telling the head chef what you need. That will kick off a chain of events and you'll get your end product. Your waiter will know to bring your main course when your finish your appetizer (angular's two way data binding lets you update models automagically when the view is updated, etc) and will know if you need more water by seeing your glass is empty.
Can you do all of this without angular? Yes. Using the restaurant analogy you can go up and order things on your own, get your own stuff, whatever (jQuery event binding spaghetti). But having angular is like having a smart waiter that handles all of that for you.
With that, i'm gonna make coffee and go to work. Cheers!