I have two TS repository classes
1) InvoiceRepository 2) SalesReceiptRepositroy
Here is how there constructor looks like
InvoiceRepository
export class InvoiceRepository extends RepositoryBase {
constructor(
protected http: Http,
protected toasterService: ToasterService,
protected progressbarService: ProgressBarService,
invocieType: InvoiceType = InvoiceType.Invoice,
@Inject('ApiEndpoint') protected apiEndpoint: string) {
super(toasterService, progressbarService);
console.log(invocieType);
}
}
SalesReceiptRepositroy
export class SalesReceiptsRepository extends InvoiceRepository {
constructor(http: Http,
toasterService: ToasterService,
progressbarService: ProgressBarService,
@Inject('ApiEndpoint') apiEndpoint: string) {
super(http, toasterService, progressbarService, InvoiceType.InvoiceCC, apiEndpoint);
}
}
Questions:
1) I’m inheriting SalesReceiptRepository from InvoiceRepository, I have to pass all the required parameters to super class constructor. Would Angular separately inject dependency to Base class and Derived class when SalesReceiptRepoistory object get’s created? OR The base class will take from it’s derived class? Little confuse, please briefly explain how these two works together
2) If you look at the InvocieRepository constructor 3rd parameter, InvoiceType is an enum and I’m defaulting it to first value. But in the console statement, it’s logging value api/ which is actually the value of 4th parameter. So, what it’s doing, setting both 3rd and 4th parameter value to api/ where the 3rd one should be 1. This is only happening when InvoiceRepository object get’screated, however it behaves well when SalesReceipRepository object get’s created. Why?
provide(InvoiceType: {useValue: InvoiceType.SomeItem})somewhere?InvoiceRepositoryinstance created by DI. However in case ofSalesReceiptRepository, I manually calling the base classconstructorso it appears to be working correctly.?at the end (invocieType?: InvoiceType = ...)of the parameter name to mark it as optional. It might also be necessary to move optional parameters at the end of the parameter list (not sure about this).Parameter can not have question mark and Initializerquestion markbut then getting run time errorNo provider for Number