I want a single token to be resolve in two different services at run time in angular component. I am adding the tokens to providers array in module as written below.
providers: [{
provide: ACCOUNT_SERVICE,
useClass: AccountServiceOne
},
{
provide: ACCOUNT_SERVICE,
useClass: AccountServiceTwo
}]
I want to use the ACCOUNT_SERVICE
token in two different classes. In AccountServiceA
, I want the token to resolve to AccountServiceOne
and in AccountServiceB
, I want the token to resolve to AccountServiceTwo
. See below.
@Injectable({ providedIn: 'root' })
export class AccountServiceA {
public constructor(
@Inject(ACCOUNT_SERVICE)
) {
}
}
@Injectable({ providedIn: 'root' })
export class AccountServiceB {
public constructor(
@Inject(ACCOUNT_SERVICE)
) {
}
}
Is it possible to resolve this at runtime?