I’m in love with Angular.js. There, I said it.

Angular.js, how I love thee. Let me count the ways:

  1. For how you let me truly separate consumers of an api from the api itself.
  2. For how you implement bidirectional binding and make ajax calls easily.

The entire time I’ve been writing rails code, I’ve felt it’s been messy having the view logic able to access variables in the controller. It’s better than your run-of-the-mill outsourced php code, but there’s still a long ways to go.

Truly, rails views should be consumers of an API just like any other external app would be.

Here’s an example: you have a portfolio website for photographers. Let’s call it, say… clickbooq.com ;-D.

For this site to serve as a functioning business, you will need to have marketing pages to sell memberships to users, a cms for users to manage their pages, some support pages for them to get help, and integration to an ecommerce platform, (amongst others).

Even if you’re writing the cms portion of the app as a separate app in rails, things still get messy within the app itself once you consider dashboard pages, internal help pages, etc (which can’t really follow restful naming conventions since that might confuse users more than it would help) vs the resources being exposed by the app.

It’s also hard to write the UI (views) and the api (controllers and models) in parallel. I mean, I guess you COULD keep things restful with regard to the models and some controllers to access them, and just have additional controllers that are 100% separate from the models and use ajax in the views to pull up resources, but then you’ve still got a page refresh and need to reload your javascript libraries every time you change pages. (I know that’s a little out of left field since we were just talking about RESTful routes and now I’m bringing up javascript load times, but it’s still an issue.)

When I talk to people about how I plan to architect a given web app solution, the vision I wish I could implement is, “We’re going to have the business logic and access to the app as one part of the app exposed through an api, and then the web front end is just going to be a consumer of that api. This has the extra benefit of preparing us to implement other clients like an android or iphone app, since those clients would use the same .” Great in theory, but with traditional views that falls apart and the webapp departs from RESTful architecture very quickly.

Angular.js, on the other hand, actually lets me write apps the way I wish I were already writing them. It stays on the view layer of the app, and has its own MVC structure that lives on the client’s browser as a single-javascript app that consumes the api’s I expose in my app.

In other words, it’s exactly what I’ve always wanted.

I guess Angular.js and I just understand each other. We finish each others’ sentences in a way rails’ view layer and I never did.

3 Responses to “I’m in love with Angular.js. There, I said it.”
  1. Igor Minar says:

    Nice post. Almost poetic. Thanks for the praise. 🙂

  2. Igor Minar says:

    Would you like an angular t-shirt?