Книга: Angular 2 Cookbook
Назад: Adding route authentication controls with route guards
Дальше: Injecting a simple service into a component

Chapter 7. Services, Dependency Injection, and NgModule

This chapter will cover the following recipes:

  • Injecting a simple service into a component
  • Controlling service instance creation and injection with NgModule
  • Service injection aliasing with useClass and useExisting
  • Injecting a value as a service with useValue and OpaqueTokens
  • Building a provider-configured service with useFactory

Introduction

Angular 1 gave you a hodgepodge of different service types. Many of them had a great deal of overlap. Many of them were confusing. And all of them were singletons.

Angular 2 has totally thrown away this concept. In its place, there is a shiny new dependency injection system that is far more extensible and sensible than its predecessor. It allows you to have atomic and non-atomic service types, aliasing, factories, and all kinds of incredibly useful tools for use in your application.

If you are looking to use services much in the same way as earlier, you will find that your understanding of service types will easily carry over to the new system. But for developers who want more out of their applications, the new world of dependency injection is incredibly powerful and obviously built for applications that can scale.

Назад: Adding route authentication controls with route guards
Дальше: Injecting a simple service into a component

thank you
Flame
cant read the code since it is all on a single line. Also this comments section is russian
Rakuneque
DATA COLLECTION AND ANALYSIS Two reviewers extracted data and assessed methodological quality independently lasix torsemide conversion Many others were in that space already