标签:
$state
ui.router.state
$state
service is responsible for representing states as well as transitioning between them. It also provides interfaces to ask for current state or even states you‘re coming from.
Returns the state configuration object for any specific state or all states.
Param | Type | Details |
---|---|---|
stateOrName
(optional)
|
stringobject |
(absolute or relative) If provided, will only get the config for the requested state. If not provided, returns an array of ALL state configs. |
context
(optional)
|
stringobject |
When stateOrName is a relative state reference, the state will be retrieved relative to context. |
Object|Array |
State configuration object or array of all objects. |
Convenience method for transitioning to a new state. $state.go
calls $state.transitionTo
internally but automatically sets options to { location: true, inherit: true, relative: $state.$current, notify: true }
. This allows you to easily use an absolute or relative to path and specify only the parameters you‘d like to update (while letting unspecified parameters inherit from the currently active ancestor states).
Param | Type | Details |
---|---|---|
to | string |
Absolute state name or relative state path. Some examples:
|
params
(optional)
|
object |
A map of the parameters that will be sent to the state, will populate $stateParams. Any parameters that are not specified will be inherited from currently defined parameters. This allows, for example, going to a sibling state that shares parameters specified in a parent state. Parameter inheritance only works between common ancestor states, I.e. transitioning to a sibling will get you the parameters for all parents, transitioning to a child will get you all current parameters, etc. |
options
(optional)
|
object |
Options object. The options are:
|
promise |
A promise representing the state of the new transition. Possible success values:
|
A url generation method that returns the compiled url for the given state populated with the given params.
Param | Type | Details |
---|---|---|
stateOrName | stringobject |
The state name or state object you‘d like to generate a url from. |
params
(optional)
|
object |
An object of parameter values to fill the state‘s required parameters. |
options
(optional)
|
object |
Options object. The options are:
|
string |
compiled state url |
A method to determine if the current active state is equal to or is the child of the state stateName. If any params are passed then they will be tested for a match as well. Not all the parameters need to be passed, just the ones you‘d like to test for equality.
Param | Type | Details |
---|---|---|
stateOrName | string |
A partial name, relative name, or glob pattern to be searched for within the current state name. |
params
(optional)
|
object |
A param object, e.g. |
options
(optional)
|
object |
An options object. The options are:
|
boolean |
Returns true if it does include the state |
Partial and relative names
Basic globbing patterns
Similar to $state.includes, but only checks for the full state name. If params is supplied then it will be tested for strict equality against the current active params object, so all params must match with none missing and no extras.
Param | Type | Details |
---|---|---|
stateOrName | stringobject |
The state name (absolute or relative) or state object you‘d like to check. |
params
(optional)
|
object |
A param object, e.g. |
options
(optional)
|
object |
An options object. The options are:
|
boolean |
Returns true if it is the state. |
A method that force reloads the current state. All resolves are re-resolved, controllers reinstantiated, and events re-fired.
Param | Type | Details |
---|---|---|
state
(optional)
|
string=object |
|
promise |
A promise representing the state of the new transition. See $state.go. |
reload()
is just an alias for:
Low-level method for transitioning to a new state. $state.go uses transitionTo
internally. $state.go
is recommended in most situations.
Param | Type | Details |
---|---|---|
to | string |
State name. |
toParams
(optional)
|
object |
A map of the parameters that will be sent to the state, will populate $stateParams. |
options
(optional)
|
object |
Options object. The options are:
|
promise |
A promise representing the state of the new transition. See $state.go. |
A param object, e.g. {sectionId: section.id)}, that you‘d like to test against the current active state.
A reference to the state‘s config object. However you passed it in. Useful for accessing custom data.
Currently pending transition. A promise that‘ll resolve or reject.
Fired when an error occurs during transition. It‘s important to note that if you have any errors in your resolve functions (javascript errors, non-existent services, etc) they will not throw traditionally. You must listen for this $stateChangeError event to catch ALL errors.
Param | Type | Details |
---|---|---|
event | Object |
Event object. |
toState | State |
The state being transitioned to. |
toParams | Object |
The params supplied to the |
fromState | State |
The current state, pre-transition. |
fromParams | Object |
The params supplied to the |
error | Error |
The resolve error object. |
Fired when the state transition begins. You can use event.preventDefault()
to prevent the transition from happening and then the transition promise will be rejected with a ‘transition prevented‘
value.
Param | Type | Details |
---|---|---|
event | Object |
Event object. |
toState | State |
The state being transitioned to. |
toParams | Object |
The params supplied to the |
fromState | State |
The current state, pre-transition. |
fromParams | Object |
The params supplied to the |
Fired once the state transition is complete.
Param | Type | Details |
---|---|---|
event | Object |
Event object. |
toState | State |
The state being transitioned to. |
toParams | Object |
The params supplied to the |
fromState | State |
The current state, pre-transition. |
fromParams | Object |
The params supplied to the |
Fired when a requested state cannot be found using the provided state name during transition. The event is broadcast allowing any handlers a single chance to deal with the error (usually by lazy-loading the unfound state). A special unfoundState
object is passed to the listener handler, you can see its three properties in the example. You can use event.preventDefault()
to abort the transition and the promise returned from go
will be rejected with a ‘transition aborted‘
value.
Param | Type | Details |
---|---|---|
event | Object |
Event object. |
unfoundState | Object |
Unfound State information. Contains: |
fromState | State |
Current state object. |
fromParams | Object |
Current state params. |
标签:
原文地址:http://www.cnblogs.com/koleyang/p/4576419.html