@Inject()is a manual mechanism for letting Angular know that a
parameter must be injected.import { Component, Inject } from '@angular/core'; import { ChatWidget } from '../components/chat-widget'; @Component({ selector: 'app-root', template: `Encryption: {{ encryption }}` }) export class AppComponent { encryption = this.chatWidget.chatSocket.encryption; constructor(@Inject(ChatWidget) private chatWidget) { } }In the above we’ve asked for
chatWidgetto be the singleton Angular
associates with theclasssymbolChatWidgetby calling
@Inject(ChatWidget). It’s important to note that we’re using
ChatWidgetfor its typings and as a reference to its singleton.
We are not usingChatWidgetto instantiate anything, Angular does
that for us behind the scenes
From https://angular-2-training-book.rangle.io/handout/di/angular2/inject_and_injectable.html