I am building an application with Angular (6.0.7
) and I am trying to create a service with the new:
@Injectable({
providedIn: \'root\'
})
I think you can't use typescript interfaces for dependency injection as typescript interfaces don't exist at runtime (only for typesafety at compile time).
I would suggest using an abstract class for it.
EDIT:
It seems you can use useClass
in the first parameter of @Injectable, not as a second like your example. Combining that with @k0zakinio's answer results in:
@Injectable({
providedIn: 'root',
useClass: environment.concrete,
deps: []
})
export abstract class SessionStorage { }
It also seems you need to declare your dependencies via deps
or inject
, checkout this github issue. I hope this time my answer is of more help.