Skip to content

Instantly share code, notes, and snippets.

@Dornhoth
Last active June 29, 2020 17:08
Show Gist options
  • Save Dornhoth/5b6e4d55749359874506fcb087d4a67a to your computer and use it in GitHub Desktop.
Save Dornhoth/5b6e4d55749359874506fcb087d4a67a to your computer and use it in GitHub Desktop.
import { Component, InjectionToken, Inject } from '@angular/core';
export const TOKEN = new InjectionToken<string>('MyToken');
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
providers: [
{ provide: TOKEN, useValue: 'my injected object 1', multi: true },
{ provide: TOKEN, useValue: 'my injected object 2', multi: true },
],
})
export class AppComponent {
constructor(@Inject(TOKEN) public myInjectObject: string) {
console.log(myInjectObject);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment