O'Reilly logo

Getting Started with Angular - Second Edition by Minko Gechev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Configuring an injector

The primitive used for the instantiation of the individual dependencies in our Angular applications via the DI mechanism of the framework is called the injector. The injector contains a set of providers that encapsulate the logic for the instantiation of registered dependencies associated with tokens. We can think of tokens as identifiers of the different providers registered within the injector.

Let's take a look at the following snippet, which is located at ch5/ts/injector-basics/injector.ts:

import 'reflect-metadata'; import { ReflectiveInjector, Inject, Injectable, OpaqueToken } from '@angular/core'; const BUFFER_SIZE = new OpaqueToken('buffer-size'); class Buffer { constructor(@Inject(BUFFER_SIZE) private size: Number) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required