Summary

We now have an app that can do a lot of stuff. It can run workouts, load workouts, save and update them, and track history. And if we look back, we have achieved this with minimal code. I can bet if we try this in standard jQuery or some other framework, it would require substantially more effort as compared to AngularJS.

We started the chapter by providing a MongoDB database on MongoLab servers. Since MongoLab provided a RESTful API to access the database, we saved some time by not setting up our own server infrastructure.

The first AngularJS construct that we touched upon was the $http service. $http is the primary service for connecting to any HTTP backend.

You learned about the $http config object and how it is used to configure any HTTP request. We also saw how the standard $http configuration helps us to readily consume server endpoints that consume and return JSON data.

You also learned how the complete $http infrastructure is based on promises and callback invocation and is totally asynchronous in nature.

For the first time, in this chapter we created our own promise and you learned how to create custom promises and resolve them.

We fixed our Personal Trainer app so it uses the $http service to load and save workout / exercise data. In the process, you also learned about issues surrounding cross-domain resource access. You learned about JSONP, a workaround to circumvent a browser's same origin restrictions and how to issue JSONP requests using Angular. We also touched upon CORS, which has emerged as a standard when it comes to cross-domain communication.

Next in line was the $resource service. This is a service that makes consuming RESTful endpoints easy. We replaced the exercise load and save implementation using $http with a $resource implementation. This refactoring resulted in more compact code that has a limited number of callbacks.

We then focused our attention on some common scenarios when dealing with remote server calls. We explored the concept of Interceptors used by AngularJS to manipulate a HTTP request/response at a global level. We created our own request interceptor to append the API key to every request made to the MongoLab server.

Then came Angular transformers that could intercept request/response message payloads and do some transformation. We saw how AngularJS uses these transformers to handle JSON data and automatically serializes and deserializes it.

Lastly, we touched upon routing failures when the route uses resolve configurations that return a promise.

We have now covered most of the building blocks of Angular, except the big one: AngularJS directives. We have used directives everywhere but have not created one. The next chapter is exclusively dedicated to AngularJS directives. We will be creating a number of small directives, such as a remote validator, AJAX button, and validation clues directive for the Workout Builder app. You will also learn how to integrate a jQuery plugin as a directive in Angular.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.17.40