Skip to content

ui-router and reusable directives #95

Closed
@stasgrom

Description

@stasgrom

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:

  1. 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:
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions