# Class StateRegistry

A registry for all of the application's [[StateDeclaration]]s

This API is found at `$stateRegistry` ([[UIRouter.stateRegistry]])

- Defined in router/state/state-registry.js:15

#####
Index

### Constructors

constructor

### Properties

$get
$injector
_root
builder
listeners
matcher
stateQueue
states
urlService
urlServiceRules
$inject

### Methods

_deregisterTree
_registerRoot
decorator
deregister
get
getStateHookBuilder
onStatesChanged
register
root

##
Constructors

### constructor

- new StateRegistry(urlService, stateService, globals, viewService): StateRegistry

- #### Parameters

  - urlService: any
  - stateService: any
  - globals: any
  - viewService: any

  #### Returns StateRegistry

  - Defined in router/state/state-registry.js:22

##
Properties

### $get

$get: (string | (($injector: InjectorService) => StateRegistry))[] = ...

- Defined in router/state/state-registry.js:52

### $injector

$injector: InjectorService

- Defined in router/state/state-registry.js:27
- Defined in router/state/state-registry.js:60

### _root

_root: StateObject

- Defined in router/state/state-registry.js:103

### builder

builder: StateBuilder

- Defined in router/state/state-registry.js:30

### listeners

listeners: any[]

- Defined in router/state/state-registry.js:28

### matcher

matcher: StateMatcher

- Defined in router/state/state-registry.js:29

### stateQueue

stateQueue: StateQueueManager

- Defined in router/state/state-registry.js:38

### states

states: {}

- Defined in router/state/state-registry.js:23

### urlService

urlService: any

- Defined in router/state/state-registry.js:25

### urlServiceRules

urlServiceRules: any

- Defined in router/state/state-registry.js:26

### `Static`$inject

$inject: string[] = ...

- Defined in router/state/state-registry.js:16

##
Methods

### _deregisterTree

- _deregisterTree(state): any[]

- #### Parameters

  - state: any

  #### Returns any[]

  - Defined in router/state/state-registry.js:171

### _registerRoot

- _registerRoot(): void

- #### Returns void

  - Defined in router/state/state-registry.js:93

### decorator

- decorator(property, builderFunction): any

- Registers a [[BuilderFunction]] for a specific [[StateObject]] property (e.g., `parent`, `url`, or `path`). More than one BuilderFunction can be registered for a given property.

  The BuilderFunction(s) will be used to define the property on any subsequently built [[StateObject]] objects.

  #### Parameters

  - property: any

    The name of the State property being registered for.

  - builderFunction: any

    The BuilderFunction which will be used to build the State property

  #### Returns any

  a function which deregisters the BuilderFunction

  - Defined in router/state/state-registry.js:233

### deregister

- deregister(stateOrName): StateObject[]

- Removes a state from the registry

  This removes a state from the registry. If the state has children, they are are also removed from the registry.

  #### Parameters

  - stateOrName: any

    the state's name or object representation

  #### Returns StateObject[]

  a list of removed states

  - Defined in router/state/state-registry.js:202

### get

- get(stateOrName, base, ...args): any

- #### Parameters

  - stateOrName: any
  - base: any
  - `Rest`...args: any

  #### Returns any

  - Defined in router/state/state-registry.js:216

### getStateHookBuilder

- getStateHookBuilder(hookName): ((stateObject: any) => ((trans: any, state: any) => any))

- This is a [[StateBuilder.builder]] function for angular1 `onEnter`, `onExit`, `onRetain` callback hooks on a [[Ng1StateDeclaration]].

  When the [[StateBuilder]] builds a [[StateObject]] object from a raw [[StateDeclaration]], this builder ensures that those hooks are injectable for @uirouter/angularjs (ng1).

  #### Parameters

  - hookName: any

  #### Returns ((stateObject: any) => ((trans: any, state: any) => any))

  - - (stateObject): ((trans: any, state: any) => any)

    - #### Parameters

      - stateObject: any

      #### Returns ((trans: any, state: any) => any)

      - - (trans, state): any

        - #### Parameters

          - trans: any
          - state: any

          #### Returns any

  #### Internalapi

  - Defined in router/state/state-registry.js:75

### onStatesChanged

- onStatesChanged(listener): any

- Listen for a State Registry events

  Adds a callback that is invoked when states are registered or deregistered with the StateRegistry.

  #### Example:

      let allStates = registry.get();

      // Later, invoke deregisterFn() to remove the listener
      let deregisterFn = registry.onStatesChanged((event, states) => {
        switch(event) {
          case: 'registered':
            states.forEach(state => allStates.push(state));
            break;
          case: 'deregistered':
            states.forEach(state => {
              let idx = allStates.indexOf(state);
              if (idx !== -1) allStates.splice(idx, 1);
            });
            break;
        }
      });

  #### Parameters

  - listener: any

    a callback function invoked when the registered states changes. The function receives two parameters, `event` and `state`. See [[StateRegistryListener]]

  #### Returns any

  a function that deregisters the listener

  - Defined in router/state/state-registry.js:137

### register

- register(stateDefinition): StateObject

- Adds a state to the registry

  Registers a [[StateDeclaration]] or queues it for registration.

  Note: a state will be queued if the state's parent isn't yet registered.

  #### Parameters

  - stateDefinition: any

    the definition of the state to register.

  #### Returns StateObject

  the internal [[StateObject]] object. If the state was successfully registered, then the object is fully built (See: [[StateBuilder]]). If the state was only queued, then the object is not fully built.

  - Defined in router/state/state-registry.js:167

### root

- root(): StateObject

- Gets the implicit root state

  Gets the root of the state tree. The root state is implicitly created by ng-router. Note: this returns the internal [[StateObject]] representation, not a [[StateDeclaration]]

  #### Returns StateObject

  the root [[StateObject]]

  - Defined in router/state/state-registry.js:152