NavController, imports and circular dependencies


#1

I am trying to create an injectable class that handles navigation (NavigationService). The class has code like:

nav.setRoot(TabsPage);

and therefore has an import of TabsPage.

On the other hand, the TabsPage component needs to inject the NavigationService.

This seems to create a circular dependency, and always fail with the following error at runtime:

Uncaught Error: Can't resolve all parameters for TabsPage: (?).

Is there a way to escape this circular dependency? Is it possible to use the NavController with strings instead of the actual page type (which causes the problem)?


#2

Generally I think injectables dealing with the view layer is something to be avoided, but I may be in the minority on that. In any event, look into forwardRef.


#3

Thanks @rapropos, it looks like the use of forwardRef solved the problem.