Tag Archives: Data Modeling
In this series we’re going to look at a 3rd party library, angular-data, for managing our data models in Angular.js.
Why use angular-data?
There are many ways to model your data in Angular. You can use the built in $http or $resource services, or you can use popular 3rd party libraries like Restangular, Breeze, or angular-data, all of which are great choices.
When I started using Angular, I, like most people, started using $http. $http feels very familiar to $.ajax from jQuery and gives you a simple API for making AJAX requests. This works great for small applications. Then I got to the point where I wanted custom methods on my models. I started taking my JSON responses and wrapping them up in custom collection and model classes/constructors. This felt very familiar coming from the Backbone world or working with an ORM on the server, as it allowed me to put business logic on models.
The previous solution works fine, but it was kind of tedious since I never abstracted that out into something reusable. During that time, I started learning Ember and Ember Data and I really liked what it offered. I wanted similar functionality for my Angular models, primarily model relationships and identity mapping. If you’re unfamiliar with an identity map, think of a person. A person has a unique identity. Regardless if a person changes jobs, name, and appearance, they still have the same identity. If my name were Douglas Crockford, the real Douglas Crockford and myself would have our own identities despite having the same name. Now think about your data / database records. In your application, if you make a request for a user object with an ID of 1, and you make another AJAX request for the user with an ID of 1, you’re going to have 2 user objects with an ID of 1 which represent the same person but they are different objects in memory. Many times in web applications you need a reference to the same “user with an ID of 1” instance, not a copy of it. Identity mapping is a pattern that allows you to return the same user with an ID of 1 instance, regardless of how many times you look it up. I learned about this pattern as I was digging into Ember Data of the Ember.js framework. The Ember Guides have a great explanation on it so be sure to read that.
angular-data was inspired by Ember Data. If you haven’t worked with Ember Data, it is an awesome modeling layer created by the Ember team. angular-data offers more features than what I just mentioned, but these 2 features were the reasons I decided to learn it and use in an application I am building at work. Anyways, let’s get into the basics of angular-data.
Role : Informatica Developer
Location: Pleasanton, CA
Duration: 1+ year Contract
Note: Send your resume at firstname.lastname@example.org or you can also reach me at (402) 905 9212. Please share or like this post.
• Participate in managing code and configurations for multiple environments, release management process, creating and maintaining environment configurations and controls, code integrity and work closely with platform team
• Ability to coordinate across teams, working closely with peers to ensure the appropriate focus and sense of urgency is applied to all production issues
• Work with third party suppliers and vendors for support, upgrades and implementations
• Serve as a mentor to junior level associates who will provide backup in your absence
• Provide assistance in root cause analysis for service interruptions
• Interface with and provide technical leadership to others in the IT division and business to address ongoing business needs
• Document the application infrastructure and teach/share with others as necessary
• Participation in projects; providing work estimates, partnering with others to design and execute on projects that enhance system availability or application capabilities