Remove cyclical vendor dependency in ionic 3 application

I include the provider in another provider in the ionic 3 application. But this gives me the error "No provider found." I did some research and found that this is due to cyclical dependence. How can I overcome circular dependence in ionic app 3?

+4
source share
2 answers

Angular does not allow you to refer to a provider in another, as this can lead to a cyclic dependency injection. The way I solved this is to remove the class variable declaration from the constructor and use the Injector from the angular kernel to inject the dependency into the timeout using the following code:

, A 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));
  }
}
+3

, , , . , , .

0

Source: https://habr.com/ru/post/1688074/


All Articles