Description
Hi,
we have several reusable components in our application, which we implemented as directives. We can plant such a component in some place in the application, and associate a state (and subsequently a specific URL) with it, so it becomes visible as soon as the URL is entered (or some user action is performed, leading to transition to the state).
The problem I'm having is the following: we want this directive to add new states to the system, relative to the parent view it is displayed in. But I am having trouble doing it. The issue is I seem to need a way to add new states/routes dynamically, when the directive becomes active (i.e. its controller is called). So I thought I could provide the directive a name of the parent state as a parameter and it could bind new states to this parent state, however:
- The $stateProvider is not available for dependency injection in the controller. I kind of bypass this problem by providing a service that returns the $stateProvider, and inject this service, but:
- Adding new states to the $stateProvider doesn't seem to work at this stage. It seems like the new states are not properly registered.
So my question is: are there any good practices on using the ui-router with reusable directives that want to provide their own states? Are there any forward looking thoughts on providing a way to dynamically register new states during the run of the application and not only during its initialization?
Thanks.