Skip to content

Instantly share code, notes, and snippets.

@Dornhoth
Last active June 29, 2020 17:07
Show Gist options
  • Save Dornhoth/1f34f889bb3376af9211d5ee1ad76c07 to your computer and use it in GitHub Desktop.
Save Dornhoth/1f34f889bb3376af9211d5ee1ad76c07 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' }]
})
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