Hello,

You can find tutorial/example here: https://www.inversionofcontrol.co.uk/injection-tokens-in-angular/

So it's something along the lines of:

export const ROUTER_SCROLL_SERVICE = new InjectionToken<string>('RouterScrollService');

Then in your module, you add it to the providers array like this:

@NgModule({

...

providers: [

{

provide: ROUTER_SCROLL_SERVICE,

useClass: RouterScrollServiceImpl

}

]

...

})

export class AppModule { }

The benefit of this approach is that you can inject the interface (thanks to the injection token) in your components instead of the implementation, meaning that you can easily mock out that dependency for tests.

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store