I am including a provider in another provider in ionic 3 app. But it is giving me error 'No Provider Found'. I did some research and found that it is due to circular dependency. How can I overcome circular dependency in ionic 3 app?
Angular doesn't allow referencing a provider in another one as it may lead to circular dependance injection. The way I solved it was removing declaration of class variable from the constructor and using Injector from angular core to inject dependancy in timeout using the following code:
So suppose you want to include Provider A in Provider B,
import { ProviderA } from '../provider-a/provider-a';
export class ProviderB {
provider_a:any;
constructor(public injector: Injector) {
console.log('Hello ProviderB Provider');
setTimeout(() => this.provider_a = injector.get(ProviderA));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With