See -edit- for updated information.
Normal states are added to $stateProvider during the configuration phase. If you want to add states at runtime, you need to save the link to $stateProvider .
This code has not been verified, but should do what you want. It creates a service called runtimeStates . You can enter it at runtime, and then add states.
// config-time dependencies can be injected here at .provider() declaration myapp.provider('runtimeStates', function runtimeStates($stateProvider) { // runtime dependencies for the service can be injected here, at the provider.$get() function. this.$get = function($q, $timeout, $state) { // for example return { addState: function(name, state) { $stateProvider.state(name, state); } } } });
I implemented some things called Future States in Additional Features of the UI-Router that take care of some of the corner cases for you, like displaying URLs in states that don't exist yet. Future states also show how lazy you are to download source code for runtime states. Take a look at the source code to understand what is related to it.
-edit- for UI-Router 1.0 +
In UI-Router 1.0, states can be registered and logged into the account at runtime using StateRegistry.register and StateRegistry.deregister .
To access StateRegistry, enter it $stateRegistry or enter $uiRouter and access it through UIRouter.stateRegistry .
UI-Router 1.0 also includes Future States out of the box, which handles lazy loading of state definitions, even syncing to a URL.
Chris T Sep 16 '14 at 15:31 2014-09-16 15:31
source share