Dependency Injection and Services

In this chapter, we're going to take a look at dependency injection (DI). While DI is not something that you have to program directly in Angular (since Angular takes care of all the DI plumbing for us), it still is something that is very useful to understand. This is because Angular makes heavy use of DI when managing its services, as well as any custom services that you are likely to write as you create your Angular applications. 

We'll be looking at one of Angular's most important built-in services, its HTTP service, in the next chapter, Chapter 12, Integrating Backend Data Services. Without the HTTP service, our applications would be super boring, since they would be unable to send data to, or receive data from, an outside source (including our own backend APIs). And so this chapter will serve us well in terms of helping us gain an understanding of how Angular injects services such as its HTTP service into our applications for us to use. Moreover, this topic is a perfect segue into the next chapter.

Here is a list of the topics that we're going to cover in this chapter:

  • What is DI?
  • What problem does it solve?
  • Additional advantages of using DI
  • Revealing the magic that Angular uses to make it all work
  • How we can guard against code minification (and why we need to)

By the end of this chapter, you'll have a solid grasp on what this often misunderstood software design pattern is, and, more importantly, how it works. Dare I say, you may even start to feel more technically advanced than most of your peers. Many developers sometimes struggle to even define DI—because it does take some effort to wrap your mind around it.

Without further ado, let's get started and discover what DI is all about by injecting some more software design knowledge into our heads. 

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

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