I have an abstract class and an implementation of it
export abstract class IPrint {
abstract Print(textInput: string): void;
}
export class FilePrint implements IPrint {
Print(textInput: string): void {
console.log("File Print");
}
}
Then introduce to Angular DI:
providers:
[
{ provide: IPrint, useClass: FilePrint }
],
I can use it like the following :
constructor(private _print: IPrint) { }
ngOnInit(): void {
console.log(this._print.Print("HI"))
}
Now I want to have multi implementation of IPrint
export class ScreenPrint implements IPrint {
Print(textInput: string): void {
console.log("Screen Print")
}
}
Then introduce to Angular DI:
providers:
[
{ provide: IPrint, useClass: FilePrint },
{ provide: IPrint, useClass: ScreenPrint }
],
When I want to use IPrint, angular does not know which implementation must use :
constructor(private _print: IPrint) { }