5. In Angular, the promises are created by
the service $q.
● Based on Kris Kowal promises mechanism that is called Q: https:
//github.com/kriskowal/q
● Used by community.
● Is integrated with the $rootScope.
● It is a basic version of the Q library containing the features required for
asynchronous communication.
6. ● The Deferred API methods (just what you need to know):
- reject(reason) - Creates a promise that is resolved as rejected by the last
reason as a parameter.
- resolve(value) - Resolve the promise with the value passed as a parameter.
7. ● The Promise API methods (just what you need to know):
- then(successCallback, errorCallback, notifyCallback) - calls one of the
success or error callbacks asynchronously as soon as the result is available.
- catch(errorCallback) - shorthand for promise.then(null, errorCallback).
8. ● When the promise is resolved
successfully, the first function
passed as parameter “then”
function returns a response object.
● When an error
occurs, the catch
function has the
result of the
operation.
9. ● With $http service methods:
- success - this callback will be called asynchronously when the response is
available.
- error - called asynchronously if an error occurs or server returns response
with an error status.
10. ● How can i synchronize multiple asynchronous functions and avoid
Javascript callback problems?
Answer: Use the $ q.all function, for combines multiple promises into a single
promise.
11. ● With $routeProvider.when method:
Only will be redirected to
“/allNames” when the
“allNamesFactory”
service promise is
resolved.