Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save muhammadghazali/8370185 to your computer and use it in GitHub Desktop.
Save muhammadghazali/8370185 to your computer and use it in GitHub Desktop.
Chapters of Mastering Web ApplicationDevelopment with AngularJS

Book contents

  • Chapter 1: Angular Zen
  • Chapter 2: Building and Testing

Chapter 3: Communicating with a Back-end Server

  • The Promise API with $q
    • Learning $q service basics
      • Working with promises and the $q service
  • Promises are first-class JavaScript objects

Chapter 4: Displaying and Formatting Data

  • Naming conventions for AngularJS directives.
  • Solutions for conditionally showing and hiding blocks of markup.
  • Usage patterns and pitfalls of the repeater ( ng-repeat ) directive.
  • Registering DOM event handlers so users can interact with an application.
  • Limitations of the AngularJS DOM-based template language and possible workarounds.
  • Filters: their purpose and usage samples. We will go over built-in filters as well as how to create and test a custom filter.

Chapter 5: Creating advanced forms

  • Model data binding and input directives
  • Form Validation
  • Nested and Repeated Forms
  • Form Submission
  • Resetting a Form

Chapter 6: Organizing Navigation

Chapter 7: Securing Your Application

Chapter 8: Building Your Own Directives

Chapter 9: Building Advanced Directives

Chapter 10: Building AngularJS Web Applications for an International Audience

Chapter 11: Writing Robust AngularJS Web Applications

Chapter 12: Packaging and Deploying AngularJS Web Applications

http://www.packtpub.com/angularjs-web-application-development/book

@muhammadghazali
Copy link
Author

Chapter 3 Notes

The main idea behind the Promise API is to bring to the asynchronous world the same ease of functions calls chaining and error handling as we can enjoy in the synchronous programming world.

AngularJS comes with the $q service a very lightweight Promise API implementation. So we need to get
familiar with $q in order to use those services effectively. So we need to get
familiar with $q in order to use those services effectively
.

$q.defer() method which returns a deferred object. Conceptually it represents a task that will be completed (or will fail in the future). The deffered object has two roles:

  • It holds a promise object (in the promise property). Promises are placeholders for the future results (success or failure) of a deferred task.
  • It exposes methods to trigger future task completion ( resolve ) or failure ( reject ).

There are always two players in the Promise API: one that controls future task execution (can invoke methods on the deferred object) and another one that depends on the results of the future task execution (holds onto promised results).

The deferred object represents a task that will complete or fail in the future. A promise object is a placeholder for the future results of this task completion.

If the error callback in .then() is omitted and a future task fails, this failure will be silently ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment