Skip to content

Latest commit

 

History

History
32 lines (29 loc) · 1.96 KB

File metadata and controls

32 lines (29 loc) · 1.96 KB

Module 5 - Angular Dependency Injection and Promises

Projects:

fun-with-di Introduction to angular Dependency Injection
fun-with-promises Introduction to Promises in Javascript

Introduction to Dependency Injection

  • We talked about the motivation to use a dependency injection infrastructure
  • We saw how to create a service - an object encapsulating a bit of logic and perhaps data
  • We defined the terms:
    • Consumer - the object that requires dependency
    • Injection request - A consumer that asks for a dependency (service) in the constructor
    • Injector - An object responsible for resolving (providing, injecting) the injection request
    • Provider - The algorithm, or logic, used to resolve the injected object
  • We saw how to define injecter and provider using the providers property of a Module, or Component
  • We understood the effect of defining a component as injector, and how to use the component hierarchy as injector hierarchy
  • We saw how to define a provider that used another class instead of the requested class
  • We saw how to use the following explicit providers:
    • Class provider
    • Existing provider
    • Value provider
    • Factory provider
  • Finally, we saw how to define a service as Injectable so it can also consume dependencies
    • We saw the "tree shakable" syntax that uses the @Injectable decorator to set the root provider

Introduction to Promises and Async Development

  • We defined a promise as an object that tells us if an action that takes time has completed, and what is the result
  • We saw that we can not "pull" that information, but rather have to use the .then and .catch methods and provide callbacks that will be called when the promise completes
  • We saw how to create a promise using the Promise Constructor.
  • We understood what async and await keywords do and how do they affect the compilation