Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Getting Started with Angular - Second edition
  • Toc
  • feedback
Getting Started with Angular - Second edition

Getting Started with Angular - Second edition

By : Minko Gechev
close
Getting Started with Angular - Second edition

Getting Started with Angular - Second edition

By: Minko Gechev

Overview of this book

Want to build quick and robust web applications with Angular? This book is the quickest way to get to grips with Angular and take advantage of all its new features.
Table of Contents (9 chapters)
close

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) {
    console.log(this.size);
  }
}

@Injectable()
class Socket {
  constructor(private buffer: Buffer) {}
}

let injector = ReflectiveInjector...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete