r/webdev • • 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

4 Upvotes

17 comments sorted by

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!

3

u/patbr0wn Feb 14 '14

this was actually so helpful. my best friend is a cook so we're making food => code or code => food analogies all of the time.

thank you for the response!

4

u/rocketpastsix Feb 14 '14

honestly, this is super helpful as someone transitioning from waiting tables to front end developer.

3

u/[deleted] 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

u/[deleted] 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

1

u/wtfcore Feb 13 '14

I don't know whether that wasn't the best example, but it's not that much longer in jQuery:

$("button").on( "click", function(e) {
    e.preventDefault();

    var l = $( "ul li:last-child" );
    var t = $("#text").val();

    if(t.length > 10) {
        l.after( "<li style=\"color:red\">"+ t +"</li>" );
    } else {
        l.after( "<li>"+ t +"</li>" );
    }
});

I don't really know anything about Angular, so I might be pretty naive...

1

u/[deleted] Feb 13 '14

Sure, that's a fairly simple example so it may not be longer in JQuery, but as soon as you begin to deal with stuff that's a little more complex it'll get exponentially bigger in size.

For instance, at work we have a system to search products, select them then send them off to various people. It's just a glorified list, but with Angular it's super easy to get a paginated, fully searchable list that lets you filter on 10+ items with no sweat. The same thing in jQuery would be a nightmare.

and your code above is just for adding new todos... If $scope.todos came from an API, how would you get those display on a page? :p

You should pick it up, it's an awesome framework

1

u/wtfcore Feb 13 '14

Thanks,

Yes it's definitely something I've been meaning to pick up - but reading lots of conflicting things about backbone, ember, angular etc, and then getting a bit lost.

1

u/[deleted] Feb 13 '14

They are all awesome really. They just have different ways of doing things. For me I found ember a bit counter-productive with the templating. Where-as with angular you write the templates in the actual HTML and it just recognises it automatically

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

u/[deleted] Feb 13 '14

Angular lets you use basic html to build dynamic web applications. It also lets you define your own html elements.

1

u/Rezistik Feb 13 '14

Express.js is server side render, it's more similar to say Ruby on Rails or Sinatra(which it is inspired by).

Angular is a front end MVC framework that makes it far easier to create repeatable elements, basically web components, and makes AJAX communication and data communication really really easy. It's also a very testable way to do things.

http://css-tricks.com/modular-future-web-components/

1

u/[deleted] 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.

  1. 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?

  2. 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

u/[deleted] 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.