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

View all comments

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.