I am fairly new to Angular and currently trying to make sense of the code written by a more experienced developer. Please excuse me if I'm not adhering to the standard communication practices and vocabulary.
There is an abstract class called abstractDataService
with an abstract method named getEntities()
, which has two implementation classes: impl1
and impl2
The implementation class impl1
looks like this:
@Injectable()
export class impl1 extends abstractDatService{
private entities: Modal[] = [
{
id: 1,
type: "a",
name: "a1"
},
{
id: 2,
type: "a",
name: "a2"
}
];
public getEntities(): Observable<Modal[]> {
return of(this.entities);
}
}
Now, within my module, I'm attempting to inject the service as follows:
providers: [
{
provide: abstractDatService,
useClass: impl1
},
{
provide: abstractDatService,
useClass: impl2
}
]
In this scenario, when I try to retrieve the entities, they are being returned only from the impl2
class and not from impl1
I would like the implementation to return both sets of data.
Is there anyone who can assist me in resolving this issue?
EDIT :
To further explain,
I have a component where I am presenting the data in the following manner:
HEAD1
Data from impl1 // this line represents a common component where data is displayed using ngFor on the observable returned.
HEAD2
Data from impl2 // this line signifies another common component where data is displayed using ngFor on the observable returned.
The common component is responsible for displaying the Data from impl1 and Data from impl2 together.