Hacker News new | ask | show | jobs
by dignifiedquire 4908 days ago
I switched from backbone to angular about half a year ago. It was the best thing that ever happened to the project I was working on. I've rebuilt the complete interface using angular in 2 days. The original backbone version took me weeks (I learned both frameworks from the ground up while writing the interface) It was just a joy to see how databinding and promises where working hand in hand to make my life as a developer so much easier.
1 comments

As a person that switched from Backbone to Angular, can you explain models in Angular (from a Backbone standpoint)?

I've looked over the docs, and as far as I can tell there really isn't a model in Angular - not anything concrete anyway.

The docs seem to explain that any JS object is a model as long as you make some reference to it.

Or, is an angular Controller (+ some JS data structure) really a model.

Its quite confusing to me.

I can't explain in terms of Backbone but I'll do my best to clear things up for you anyway. In Angular, you have a magic $scope variable that is available both in your controller function, and in the section of HTML that the controller is bound to. Now I can set any attributes I want to the $scope variable and they will act like models for that controller.

For example. Within my controller, I set $scope.username to "alex" and this will update any HTML bound to the value "username", within the scope, to "alex". Similarly, I can set, say, $scope.settings = {user: {username: "alex"}} and this will update any HTML elements (within the scope) bound to settings.user.username to "alex".

These are very simple examples, but they show the beauty of having plain JS objects as your "models".

Angular model is just any normal js object you want, then via two way binding it gets displayed without you doing any work. Freakin awesome.