In Angular 5, if I had AbstractClassService
and ExtendedClassService
that extends the abstract, I could do this in my NgModule\'s providers array:<
I needed to do two things.
First, use implements
instead of extends
when creating the inheriting class and do not use the providedIn
key there:
@Injectable() // removed providedIn
export class ExtendedClassService implements AbstractClassService {}
Second, add the provider instructions to the abstract class instead:
@Injectable({providedIn: 'root', useClass: ExtendedClassService})
export abstract class AbstractClassService {}
Other provider configuration (useValue
, useExisting
, useFactory
) can also be used there.
Credit goes to Abinesh with this comment which led me to the linked blog post. Many thanks to the blog author!