@angular-wave/angular.ts 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/angular.d.ts +150 -0
- package/@types/animations/animate-cache.d.ts +50 -0
- package/@types/animations/animate-children-directive.d.ts +10 -0
- package/@types/animations/animate-css-driver.d.ts +18 -0
- package/@types/animations/animate-css.d.ts +18 -0
- package/@types/animations/animate-js-driver.d.ts +14 -0
- package/@types/animations/animate-js.d.ts +23 -0
- package/@types/animations/animate-queue.d.ts +28 -0
- package/@types/animations/animate-runner.d.ts +31 -0
- package/@types/animations/animate-swap.d.ts +9 -0
- package/@types/animations/animate.d.ts +450 -0
- package/@types/animations/animation.d.ts +14 -0
- package/@types/animations/interface.d.ts +17 -0
- package/@types/animations/raf-scheduler.d.ts +37 -0
- package/@types/animations/shared.d.ts +74 -0
- package/@types/core/compile/compile.d.ts +201 -0
- package/@types/core/controller/controller.d.ts +54 -0
- package/@types/core/di/injector.d.ts +22 -0
- package/@types/core/filter/filter.d.ts +23 -0
- package/@types/core/interpolate/interpolate.d.ts +38 -0
- package/@types/core/parse/ast/ast-node.d.ts +56 -0
- package/@types/core/parse/ast/ast.d.ts +164 -0
- package/@types/core/parse/lexer/lexer.d.ts +119 -0
- package/@types/core/parse/lexer/token.d.ts +17 -0
- package/@types/core/parse/parse.d.ts +33 -0
- package/@types/core/parse/parser/parser.d.ts +41 -0
- package/@types/core/sanitize/sanitize-uri.d.ts +40 -0
- package/@types/directive/aria/aria.d.ts +104 -0
- package/@types/directive/attrs/attrs.d.ts +8 -0
- package/@types/directive/bind/bind.d.ts +18 -0
- package/@types/directive/channel/channel.d.ts +10 -0
- package/@types/directive/class/class.d.ts +3 -0
- package/@types/directive/cloak/cloak.d.ts +4 -0
- package/@types/directive/controller/controller.d.ts +4 -0
- package/@types/directive/events/events.d.ts +21 -0
- package/@types/directive/form/form.d.ts +264 -0
- package/@types/directive/http/http.d.ts +46 -0
- package/@types/directive/if/if.d.ts +10 -0
- package/@types/directive/include/include.d.ts +28 -0
- package/@types/directive/init/init.d.ts +4 -0
- package/@types/directive/input/input.d.ts +70 -0
- package/@types/directive/messages/messages.d.ts +63 -0
- package/@types/directive/model/model.d.ts +515 -0
- package/@types/directive/model-options/model-options.d.ts +56 -0
- package/@types/directive/non-bindable/non-bindable.d.ts +4 -0
- package/@types/directive/observe/observe.d.ts +9 -0
- package/@types/directive/options/options.d.ts +13 -0
- package/@types/directive/ref/ref.d.ts +11 -0
- package/@types/directive/repeat/repeat.d.ts +11 -0
- package/@types/directive/script/script.d.ts +10 -0
- package/@types/directive/select/select.d.ts +15 -0
- package/@types/directive/setter/setter.d.ts +12 -0
- package/@types/directive/show-hide/show-hide.d.ts +19 -0
- package/@types/directive/style/style.d.ts +4 -0
- package/@types/directive/switch/switch.d.ts +18 -0
- package/@types/directive/transclude/transclude.d.ts +10 -0
- package/@types/directive/validators/validators.d.ts +149 -0
- package/@types/filters/filter.d.ts +4 -0
- package/@types/filters/filters.d.ts +38 -0
- package/@types/filters/limit-to.d.ts +4 -0
- package/@types/filters/order-by.d.ts +7 -0
- package/@types/index.d.ts +2 -0
- package/@types/interface.d.ts +5 -4
- package/@types/ng.d.ts +8 -0
- package/@types/router/common/trace.d.ts +66 -0
- package/@types/router/directives/state-directives.d.ts +46 -0
- package/@types/router/directives/view-directive.d.ts +138 -0
- package/@types/router/glob/glob.d.ts +81 -0
- package/@types/router/hooks/core-resolvables.d.ts +2 -0
- package/@types/router/hooks/ignored-transition.d.ts +1 -0
- package/@types/router/hooks/invalid-transition.d.ts +1 -0
- package/@types/router/hooks/lazy-load.d.ts +42 -0
- package/@types/router/hooks/on-enter-exit-retain.d.ts +3 -0
- package/@types/router/hooks/redirect-to.d.ts +4 -0
- package/@types/router/hooks/resolve.d.ts +4 -0
- package/@types/router/hooks/update-globals.d.ts +1 -0
- package/@types/router/hooks/url.d.ts +5 -0
- package/@types/router/hooks/views.d.ts +5 -0
- package/@types/router/params/interface.d.ts +606 -0
- package/@types/router/params/param-factory.d.ts +16 -0
- package/@types/router/params/param-type.d.ts +59 -0
- package/@types/router/params/param.d.ts +71 -0
- package/@types/router/params/state-params.d.ts +12 -0
- package/@types/router/path/path-node.d.ts +38 -0
- package/@types/router/path/path-utils.d.ts +88 -0
- package/@types/router/resolve/interface.d.ts +200 -0
- package/@types/router/resolve/resolvable.d.ts +50 -0
- package/@types/router/resolve/resolve-context.d.ts +93 -0
- package/@types/router/router.d.ts +47 -0
- package/@types/router/state/interface.d.ts +983 -0
- package/@types/router/state/state-builder.d.ts +95 -0
- package/@types/router/state/state-matcher.d.ts +7 -0
- package/@types/router/state/state-object.d.ts +83 -0
- package/@types/router/state/state-queue-manager.d.ts +29 -0
- package/@types/router/state/state-registry.d.ts +133 -0
- package/@types/router/state/state-service.d.ts +425 -0
- package/@types/router/state/target-state.d.ts +102 -0
- package/@types/router/state/views.d.ts +58 -0
- package/@types/router/state-filters.d.ts +39 -0
- package/@types/router/template-factory.d.ts +117 -0
- package/@types/router/transition/hook-builder.d.ts +45 -0
- package/@types/router/transition/hook-registry.d.ts +102 -0
- package/@types/router/transition/interface.d.ts +880 -0
- package/@types/router/transition/reject-factory.d.ts +43 -0
- package/@types/router/transition/transition-event-type.d.ts +24 -0
- package/@types/router/transition/transition-hook.d.ts +86 -0
- package/@types/router/transition/transition-service.d.ts +116 -0
- package/@types/router/transition/transition.d.ts +331 -0
- package/@types/router/url/url-config.d.ts +99 -0
- package/@types/router/url/url-matcher.d.ts +174 -0
- package/@types/router/url/url-rule.d.ts +161 -0
- package/@types/router/url/url-rules.d.ts +249 -0
- package/@types/router/url/url-service.d.ts +254 -0
- package/@types/router/view/interface.d.ts +44 -0
- package/@types/router/view/view.d.ts +149 -0
- package/@types/router/view-scroll.d.ts +10 -0
- package/@types/services/anchor-scroll.d.ts +25 -0
- package/@types/services/cookie-reader.d.ts +4 -0
- package/@types/services/http/http.d.ts +134 -0
- package/@types/services/http-backend/http-backend.d.ts +58 -0
- package/@types/services/sce/sce.d.ts +238 -0
- package/@types/services/template-request.d.ts +55 -0
- package/@types/shared/common.d.ts +197 -0
- package/@types/shared/hof.d.ts +108 -0
- package/@types/shared/predicates.d.ts +17 -0
- package/@types/shared/queue.d.ts +64 -0
- package/@types/shared/strings.d.ts +58 -0
- package/dist/angular-ts.esm.js +2 -3
- package/dist/angular-ts.umd.js +2 -3
- package/dist/angular-ts.umd.min.js +1 -1
- package/docs/layouts/shortcodes/version.html +1 -1
- package/package.json +1 -1
- package/src/interface.ts +5 -4
- package/src/services/pubsub/pubsub.js +0 -1
|
@@ -0,0 +1,983 @@
|
|
|
1
|
+
import { ParamDeclaration, RawParams } from "../params/interface.ts";
|
|
2
|
+
import { StateObject } from "./state-object.js";
|
|
3
|
+
import { ViewContext } from "../view/interface.ts";
|
|
4
|
+
import { Injectable } from "../../interface.ts";
|
|
5
|
+
import { Transition } from "../transition/transition.js";
|
|
6
|
+
import {
|
|
7
|
+
TransitionStateHookFn,
|
|
8
|
+
TransitionOptions,
|
|
9
|
+
} from "../transition/interface.ts";
|
|
10
|
+
import {
|
|
11
|
+
ResolvePolicy,
|
|
12
|
+
ResolvableLiteral,
|
|
13
|
+
ProviderLike,
|
|
14
|
+
} from "../resolve/interface.ts";
|
|
15
|
+
import { Resolvable } from "../resolve/resolvable.js";
|
|
16
|
+
import { TargetState } from "./target-state.js";
|
|
17
|
+
export type StateOrName = string | StateDeclaration | StateObject;
|
|
18
|
+
export interface TransitionPromise extends Promise<StateObject> {
|
|
19
|
+
transition: Transition;
|
|
20
|
+
}
|
|
21
|
+
export interface TargetStateDef {
|
|
22
|
+
state: StateOrName;
|
|
23
|
+
params?: RawParams;
|
|
24
|
+
options?: TransitionOptions;
|
|
25
|
+
}
|
|
26
|
+
export type ResolveTypes = Resolvable | ResolvableLiteral | ProviderLike;
|
|
27
|
+
/**
|
|
28
|
+
* Interface for declaring a view
|
|
29
|
+
*
|
|
30
|
+
* This interface defines the basic data that a normalized view declaration will have on it.
|
|
31
|
+
* Add any additional fields that the framework requires to that interface.
|
|
32
|
+
*/
|
|
33
|
+
export interface ViewDeclaration {
|
|
34
|
+
/**
|
|
35
|
+
* The raw name for the view declaration, i.e., the [[StateDeclaration.views]] property name.
|
|
36
|
+
*/
|
|
37
|
+
$name?: string;
|
|
38
|
+
/**
|
|
39
|
+
* The normalized address for the `ui-view` which this ViewConfig targets.
|
|
40
|
+
*
|
|
41
|
+
* A ViewConfig targets a `ui-view` in the DOM (relative to the `uiViewContextAnchor`) which has
|
|
42
|
+
* a specific name.
|
|
43
|
+
* @example `header` or `$default`
|
|
44
|
+
*
|
|
45
|
+
* The `uiViewName` can also target a _nested view_ by providing a dot-notation address
|
|
46
|
+
* @example `foo.bar` or `foo.$default.bar`
|
|
47
|
+
*/
|
|
48
|
+
$uiViewName?: string;
|
|
49
|
+
/**
|
|
50
|
+
* The normalized context anchor (state name) for the `uiViewName`
|
|
51
|
+
*
|
|
52
|
+
* When targeting a `ui-view`, the `uiViewName` address is anchored to a context name (state name).
|
|
53
|
+
*/
|
|
54
|
+
$uiViewContextAnchor?: string;
|
|
55
|
+
/**
|
|
56
|
+
* A type identifier for the View
|
|
57
|
+
*
|
|
58
|
+
* This is used when loading prerequisites for the view, before it enters the DOM. Different types of views
|
|
59
|
+
* may load differently (e.g., templateProvider+controllerProvider vs component class)
|
|
60
|
+
*/
|
|
61
|
+
$type?: string;
|
|
62
|
+
/**
|
|
63
|
+
* The context that this view is declared within.
|
|
64
|
+
*/
|
|
65
|
+
$context?: ViewContext;
|
|
66
|
+
/**
|
|
67
|
+
* The name of the component to use for this view.
|
|
68
|
+
*
|
|
69
|
+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
|
|
70
|
+
*
|
|
71
|
+
* The name of an [angular 1.5+ `.component()`](https://docs.angularjs.org/guide/component) (or directive with
|
|
72
|
+
* bindToController and/or scope declaration) which will be used for this view.
|
|
73
|
+
*
|
|
74
|
+
* Resolve data can be provided to the component via the component's `bindings` object (for 1.3+ directives, the
|
|
75
|
+
* `bindToController` is used; for other directives, the `scope` declaration is used). For each binding declared
|
|
76
|
+
* on the component, any resolve with the same name is set on the component's controller instance. The binding
|
|
77
|
+
* is provided to the component as a one-time-binding. In general, components should likewise declare their
|
|
78
|
+
* input bindings as [one-way ("<")](https://docs.angularjs.org/api/ng/service/$compile#-scope-).
|
|
79
|
+
*
|
|
80
|
+
* Note: inside a "views:" block, a bare string `"foo"` is shorthand for `{ component: "foo" }`
|
|
81
|
+
*
|
|
82
|
+
* Note: Mapping from resolve names to component inputs may be specified using [[bindings]].
|
|
83
|
+
*
|
|
84
|
+
* #### Example:
|
|
85
|
+
* ```js
|
|
86
|
+
* .state('profile', {
|
|
87
|
+
* // Use the <my-profile></my-profile> component for the Unnamed view
|
|
88
|
+
* component: 'MyProfile',
|
|
89
|
+
* }
|
|
90
|
+
*
|
|
91
|
+
* .state('messages', {
|
|
92
|
+
* // use the <nav-bar></nav-bar> component for the view named 'header'
|
|
93
|
+
* // use the <message-list></message-list> component for the view named 'content'
|
|
94
|
+
* views: {
|
|
95
|
+
* header: { component: 'NavBar' },
|
|
96
|
+
* content: { component: 'MessageList' }
|
|
97
|
+
* }
|
|
98
|
+
* }
|
|
99
|
+
*
|
|
100
|
+
* .state('contacts', {
|
|
101
|
+
* // Inside a "views:" block, a bare string "NavBar" is shorthand for { component: "NavBar" }
|
|
102
|
+
* // use the <nav-bar></nav-bar> component for the view named 'header'
|
|
103
|
+
* // use the <contact-list></contact-list> component for the view named 'content'
|
|
104
|
+
* views: {
|
|
105
|
+
* header: 'NavBar',
|
|
106
|
+
* content: 'ContactList'
|
|
107
|
+
* }
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
*
|
|
112
|
+
* Note: When using `component` to define a view, you may _not_ use any of: `template`, `templateUrl`,
|
|
113
|
+
* `templateProvider`, `controller`, `controllerProvider`, `controllerAs`.
|
|
114
|
+
*
|
|
115
|
+
*
|
|
116
|
+
* See also: Todd Motto's angular 1.3 and 1.4 [backport of .component()](https://github.com/toddmotto/angular-component)
|
|
117
|
+
*/
|
|
118
|
+
component?: string;
|
|
119
|
+
/**
|
|
120
|
+
* An object which maps `resolve`s to [[component]] `bindings`.
|
|
121
|
+
*
|
|
122
|
+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
|
|
123
|
+
*
|
|
124
|
+
* When using a [[component]] declaration (`component: 'myComponent'`), each input binding for the component is supplied
|
|
125
|
+
* data from a resolve of the same name, by default. You may supply data from a different resolve name by mapping it here.
|
|
126
|
+
*
|
|
127
|
+
* Each key in this object is the name of one of the component's input bindings.
|
|
128
|
+
* Each value is the name of the resolve that should be provided to that binding.
|
|
129
|
+
*
|
|
130
|
+
* Any component bindings that are omitted from this map get the default behavior of mapping to a resolve of the
|
|
131
|
+
* same name.
|
|
132
|
+
*
|
|
133
|
+
* #### Example:
|
|
134
|
+
* ```js
|
|
135
|
+
* $stateProvider.state('foo', {
|
|
136
|
+
* resolve: {
|
|
137
|
+
* foo: function(FooService) { return FooService.get(); },
|
|
138
|
+
* bar: function(BarService) { return BarService.get(); }
|
|
139
|
+
* },
|
|
140
|
+
* component: 'Baz',
|
|
141
|
+
* // The component's `baz` binding gets data from the `bar` resolve
|
|
142
|
+
* // The component's `foo` binding gets data from the `foo` resolve (default behavior)
|
|
143
|
+
* bindings: {
|
|
144
|
+
* baz: 'bar'
|
|
145
|
+
* }
|
|
146
|
+
* });
|
|
147
|
+
*
|
|
148
|
+
* app.component('Baz', {
|
|
149
|
+
* templateUrl: 'baz.html',
|
|
150
|
+
* controller: 'BazController',
|
|
151
|
+
* bindings: {
|
|
152
|
+
* foo: '<', // foo binding
|
|
153
|
+
* baz: '<' // baz binding
|
|
154
|
+
* }
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
*/
|
|
159
|
+
bindings?: {
|
|
160
|
+
[key: string]: string;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Dynamic component provider function.
|
|
164
|
+
*
|
|
165
|
+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
|
|
166
|
+
*
|
|
167
|
+
* This is an injectable provider function which returns the name of the component to use.
|
|
168
|
+
* The provider will invoked during a Transition in which the view's state is entered.
|
|
169
|
+
* The provider is called after the resolve data is fetched.
|
|
170
|
+
*
|
|
171
|
+
* #### Example:
|
|
172
|
+
* ```js
|
|
173
|
+
* componentProvider: function(MyResolveData, $transition$) {
|
|
174
|
+
* if (MyResolveData.foo) {
|
|
175
|
+
* return "fooComponent"
|
|
176
|
+
* } else if ($transition$.to().name === 'bar') {
|
|
177
|
+
* return "barComponent";
|
|
178
|
+
* }
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
componentProvider?: Injectable;
|
|
183
|
+
/**
|
|
184
|
+
* The view's controller function or name
|
|
185
|
+
*
|
|
186
|
+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
|
|
187
|
+
*
|
|
188
|
+
* The controller function, or the name of a registered controller. The controller function will be used
|
|
189
|
+
* to control the contents of the [[directives.uiView]] directive.
|
|
190
|
+
*
|
|
191
|
+
* If specified as a string, controllerAs can be declared here, i.e., "FooController as foo" instead of in
|
|
192
|
+
* a separate [[controllerAs]] property.
|
|
193
|
+
*
|
|
194
|
+
* See: [[Ng1Controller]] for information about component-level router hooks.
|
|
195
|
+
*/
|
|
196
|
+
controller?: Injectable | string;
|
|
197
|
+
/**
|
|
198
|
+
* A controller alias name.
|
|
199
|
+
*
|
|
200
|
+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
|
|
201
|
+
*
|
|
202
|
+
* If present, the controller will be published to scope under the `controllerAs` name.
|
|
203
|
+
* See: https://docs.angularjs.org/api/ng/directive/ngController
|
|
204
|
+
*/
|
|
205
|
+
controllerAs?: string;
|
|
206
|
+
/**
|
|
207
|
+
* Dynamic controller provider function.
|
|
208
|
+
*
|
|
209
|
+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
|
|
210
|
+
*
|
|
211
|
+
* This is an injectable provider function which returns the actual controller function, or the name
|
|
212
|
+
* of a registered controller. The provider will invoked during a Transition in which the view's state is
|
|
213
|
+
* entered. The provider is called after the resolve data is fetched.
|
|
214
|
+
*
|
|
215
|
+
* #### Example:
|
|
216
|
+
* ```js
|
|
217
|
+
* controllerProvider: function(MyResolveData, $transition$) {
|
|
218
|
+
* if (MyResolveData.foo) {
|
|
219
|
+
* return "FooCtrl"
|
|
220
|
+
* } else if ($transition$.to().name === 'bar') {
|
|
221
|
+
* return "BarCtrl";
|
|
222
|
+
* } else {
|
|
223
|
+
* return function($scope) {
|
|
224
|
+
* $scope.baz = "Qux";
|
|
225
|
+
* }
|
|
226
|
+
* }
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
controllerProvider?: Injectable;
|
|
231
|
+
/**
|
|
232
|
+
* The scope variable name to use for resolve data.
|
|
233
|
+
*
|
|
234
|
+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
|
|
235
|
+
*
|
|
236
|
+
* When a view is activated, the resolved data for the state which the view belongs to is put on the scope.
|
|
237
|
+
* This property sets the name of the scope variable to use for the resolved data.
|
|
238
|
+
*
|
|
239
|
+
* Defaults to `$resolve`.
|
|
240
|
+
*/
|
|
241
|
+
resolveAs?: string;
|
|
242
|
+
/**
|
|
243
|
+
* The HTML template for the view.
|
|
244
|
+
*
|
|
245
|
+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
|
|
246
|
+
*
|
|
247
|
+
* HTML template as a string, or a function which returns an html template as a string.
|
|
248
|
+
* This template will be used to render the corresponding [[directives.uiView]] directive.
|
|
249
|
+
*
|
|
250
|
+
* This property takes precedence over templateUrl.
|
|
251
|
+
*
|
|
252
|
+
* If `template` is a function, it will be called with the Transition parameters as the first argument.
|
|
253
|
+
*
|
|
254
|
+
* #### Example:
|
|
255
|
+
* ```js
|
|
256
|
+
* template: "<h1>inline template definition</h1><div ui-view></div>"
|
|
257
|
+
* ```
|
|
258
|
+
*
|
|
259
|
+
* #### Example:
|
|
260
|
+
* ```js
|
|
261
|
+
* template: function(params) {
|
|
262
|
+
* return "<h1>generated template</h1>";
|
|
263
|
+
* }
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
template?: Function | string;
|
|
267
|
+
/**
|
|
268
|
+
* The URL for the HTML template for the view.
|
|
269
|
+
*
|
|
270
|
+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
|
|
271
|
+
*
|
|
272
|
+
* A path or a function that returns a path to an html template.
|
|
273
|
+
* The template will be fetched and used to render the corresponding [[directives.uiView]] directive.
|
|
274
|
+
*
|
|
275
|
+
* If `templateUrl` is a function, it will be called with the Transition parameters as the first argument.
|
|
276
|
+
*
|
|
277
|
+
* #### Example:
|
|
278
|
+
* ```js
|
|
279
|
+
* templateUrl: "/templates/home.html"
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* #### Example:
|
|
283
|
+
* ```js
|
|
284
|
+
* templateUrl: function(params) {
|
|
285
|
+
* return myTemplates[params.pageId];
|
|
286
|
+
* }
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
templateUrl?: string | Function;
|
|
290
|
+
/**
|
|
291
|
+
* Injected function which returns the HTML template.
|
|
292
|
+
*
|
|
293
|
+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
|
|
294
|
+
*
|
|
295
|
+
* Injected function which returns the HTML template.
|
|
296
|
+
* The template will be used to render the corresponding [[directives.uiView]] directive.
|
|
297
|
+
*
|
|
298
|
+
* #### Example:
|
|
299
|
+
* ```js
|
|
300
|
+
* templateProvider: function(MyTemplateService, $transition$) {
|
|
301
|
+
* return MyTemplateService.getTemplate($transition$.params().pageId);
|
|
302
|
+
* }
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
templateProvider?: Injectable;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* The return value of a [[redirectTo]] function
|
|
309
|
+
*
|
|
310
|
+
* - string: a state name
|
|
311
|
+
* - TargetState: a target state, parameters, and options
|
|
312
|
+
* - object: an object with a state name and parameters
|
|
313
|
+
*/
|
|
314
|
+
export type RedirectToResult =
|
|
315
|
+
| string
|
|
316
|
+
| TargetState
|
|
317
|
+
| {
|
|
318
|
+
state?: string;
|
|
319
|
+
params?: RawParams;
|
|
320
|
+
}
|
|
321
|
+
| void;
|
|
322
|
+
/**
|
|
323
|
+
* The StateDeclaration object is used to define a state or nested state.
|
|
324
|
+
*
|
|
325
|
+
* Note: Each implementation of UI-Router (for a specific framework)
|
|
326
|
+
* extends this interface as necessary.
|
|
327
|
+
*
|
|
328
|
+
* #### Example:
|
|
329
|
+
* ```js
|
|
330
|
+
* // StateDeclaration object
|
|
331
|
+
* var foldersState = {
|
|
332
|
+
* name: 'folders',
|
|
333
|
+
* url: '/folders',
|
|
334
|
+
* component: FoldersComponent,
|
|
335
|
+
* resolve: {
|
|
336
|
+
* allfolders: function(FolderService) {
|
|
337
|
+
* return FolderService.list();
|
|
338
|
+
* }
|
|
339
|
+
* },
|
|
340
|
+
* }
|
|
341
|
+
*
|
|
342
|
+
* registry.register(foldersState);
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
export interface StateDeclaration {
|
|
346
|
+
/**
|
|
347
|
+
* The state name (required)
|
|
348
|
+
*
|
|
349
|
+
* A unique state name, e.g. `"home"`, `"about"`, `"contacts"`.
|
|
350
|
+
* To create a parent/child state use a dot, e.g. `"about.sales"`, `"home.newest"`.
|
|
351
|
+
*
|
|
352
|
+
* Note: [State] objects require unique names.
|
|
353
|
+
* The name is used like an id.
|
|
354
|
+
*/
|
|
355
|
+
name?: string;
|
|
356
|
+
/**
|
|
357
|
+
* Abstract state indicator
|
|
358
|
+
*
|
|
359
|
+
* An abstract state can never be directly activated.
|
|
360
|
+
* Use an abstract state to provide inherited properties (url, resolve, data, etc) to children states.
|
|
361
|
+
*/
|
|
362
|
+
abstract?: boolean;
|
|
363
|
+
/**
|
|
364
|
+
* The parent state
|
|
365
|
+
*
|
|
366
|
+
* Normally, a state's parent is implied from the state's [[name]], e.g., `"parentstate.childstate"`.
|
|
367
|
+
*
|
|
368
|
+
* Alternatively, you can explicitly set the parent state using this property.
|
|
369
|
+
* This allows shorter state names, e.g., `<a ui-sref="childstate">Child</a>`
|
|
370
|
+
* instead of `<a ui-sref="parentstate.childstate">Child</a>
|
|
371
|
+
*
|
|
372
|
+
* When using this property, the state's name should not have any dots in it.
|
|
373
|
+
*
|
|
374
|
+
* #### Example:
|
|
375
|
+
* ```js
|
|
376
|
+
* var parentstate = {
|
|
377
|
+
* name: 'parentstate'
|
|
378
|
+
* }
|
|
379
|
+
* var childstate = {
|
|
380
|
+
* name: 'childstate',
|
|
381
|
+
* parent: 'parentstate'
|
|
382
|
+
* // or use a JS var which is the parent StateDeclaration, i.e.:
|
|
383
|
+
* // parent: parentstate
|
|
384
|
+
* }
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
parent?: string | StateDeclaration;
|
|
388
|
+
/**
|
|
389
|
+
* Gets the internal State object API
|
|
390
|
+
*
|
|
391
|
+
* Gets the *internal API* for a registered state.
|
|
392
|
+
*
|
|
393
|
+
* Note: the internal [[StateObject]] API is subject to change without notice
|
|
394
|
+
* @internal
|
|
395
|
+
*/
|
|
396
|
+
$$state?: () => StateObject;
|
|
397
|
+
/**
|
|
398
|
+
* Resolve - a mechanism to asynchronously fetch data, participating in the Transition lifecycle
|
|
399
|
+
*
|
|
400
|
+
* The `resolve:` property defines data (or other dependencies) to be fetched asynchronously when the state is being entered.
|
|
401
|
+
* After the data is fetched, it may be used in views, transition hooks or other resolves that belong to this state.
|
|
402
|
+
* The data may also be used in any views or resolves that belong to nested states.
|
|
403
|
+
*
|
|
404
|
+
* ### As an array
|
|
405
|
+
*
|
|
406
|
+
* Each array element should be a [[ResolvableLiteral]] object.
|
|
407
|
+
*
|
|
408
|
+
* #### Example:
|
|
409
|
+
* The `user` resolve injects the current `Transition` and the `UserService` (using its token, which is a string).
|
|
410
|
+
* The [[ResolvableLiteral.resolvePolicy]] sets how the resolve is processed.
|
|
411
|
+
* The `user` data, fetched asynchronously, can then be used in a view.
|
|
412
|
+
* ```js
|
|
413
|
+
* var state = {
|
|
414
|
+
* name: 'user',
|
|
415
|
+
* url: '/user/:userId
|
|
416
|
+
* resolve: [
|
|
417
|
+
* {
|
|
418
|
+
* token: 'user',
|
|
419
|
+
* policy: { when: 'EAGER' },
|
|
420
|
+
* deps: ['UserService', Transition],
|
|
421
|
+
* resolveFn: (userSvc, trans) => userSvc.fetchUser(trans.params().userId) },
|
|
422
|
+
* }
|
|
423
|
+
* ]
|
|
424
|
+
* }
|
|
425
|
+
* ```
|
|
426
|
+
*
|
|
427
|
+
* Note: an Angular 2 style [`useFactory` provider literal](https://angular.io/docs/ts/latest/cookbook/dependency-injection.html#!#provide)
|
|
428
|
+
* may also be used. See [[ProviderLike]].
|
|
429
|
+
* #### Example:
|
|
430
|
+
* ```
|
|
431
|
+
* resolve: [
|
|
432
|
+
* { provide: 'token', useFactory: (http) => http.get('/'), deps: [ Http ] },
|
|
433
|
+
* ]
|
|
434
|
+
* ```
|
|
435
|
+
*
|
|
436
|
+
* ### As an object
|
|
437
|
+
*
|
|
438
|
+
* The `resolve` property may be an object where:
|
|
439
|
+
* - Each key (string) is the name of the dependency.
|
|
440
|
+
* - Each value (function) is an injectable function which returns the dependency, or a promise for the dependency.
|
|
441
|
+
*
|
|
442
|
+
* This style is based on AngularTS injectable functions, but can be used with any UI-Router implementation.
|
|
443
|
+
* If your code will be minified, the function should be ["annotated" in the AngularTS manner](https://docs.angularjs.org/guide/di#dependency-annotation).
|
|
444
|
+
*
|
|
445
|
+
* #### AngularTS Example:
|
|
446
|
+
* ```js
|
|
447
|
+
* resolve: {
|
|
448
|
+
* // If you inject `myStateDependency` into a controller, you'll get "abc"
|
|
449
|
+
* myStateDependency: function() {
|
|
450
|
+
* return "abc";
|
|
451
|
+
* },
|
|
452
|
+
* // Dependencies are annotated in "Inline Array Annotation"
|
|
453
|
+
* myAsyncData: ['$http', '$transition$' function($http, $transition$) {
|
|
454
|
+
* // Return a promise (async) for the data
|
|
455
|
+
* return $http.get("/foos/" + $transition$.params().foo);
|
|
456
|
+
* }]
|
|
457
|
+
* }
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* Note: You cannot specify a policy for each Resolvable, nor can you use non-string
|
|
461
|
+
* tokens when using the object style `resolve:` block.
|
|
462
|
+
*
|
|
463
|
+
* ### Lifecycle
|
|
464
|
+
*
|
|
465
|
+
* Since a resolve function can return a promise, the router will delay entering the state until the promises are ready.
|
|
466
|
+
* If any of the promises are rejected, the Transition is aborted with an Error.
|
|
467
|
+
*
|
|
468
|
+
* By default, resolves for a state are fetched just before that state is entered.
|
|
469
|
+
* Note that only states which are being *entered* during the `Transition` have their resolves fetched.
|
|
470
|
+
* States that are "retained" do not have their resolves re-fetched.
|
|
471
|
+
*
|
|
472
|
+
* If you are currently in a parent state `parent` and are transitioning to a child state `parent.child`, the
|
|
473
|
+
* previously resolved data for state `parent` can be injected into `parent.child` without delay.
|
|
474
|
+
*
|
|
475
|
+
* Any resolved data for `parent.child` is retained until `parent.child` is exited, e.g., by transitioning back to the `parent` state.
|
|
476
|
+
*
|
|
477
|
+
* Because of this scoping and lifecycle, resolves are a great place to fetch your application's primary data.
|
|
478
|
+
*
|
|
479
|
+
* ### Injecting resolves into other things
|
|
480
|
+
*
|
|
481
|
+
* During a transition, Resolve data can be injected into:
|
|
482
|
+
*
|
|
483
|
+
* - Views (the components which fill a `ui-view` tag)
|
|
484
|
+
* - Transition Hooks
|
|
485
|
+
* - Other resolves (a resolve may depend on asynchronous data from a different resolve)
|
|
486
|
+
*
|
|
487
|
+
* ### Injecting other things into resolves
|
|
488
|
+
*
|
|
489
|
+
* Resolve functions usually have dependencies on some other API(s).
|
|
490
|
+
* The dependencies are usually declared and injected into the resolve function.
|
|
491
|
+
* A common pattern is to inject a custom service such as `UserService`.
|
|
492
|
+
* The resolve then delegates to a service method, such as `UserService.list()`;
|
|
493
|
+
*
|
|
494
|
+
* #### Special injectable tokens
|
|
495
|
+
*
|
|
496
|
+
* - `UIRouter`: The [[UIRouter]] instance which has references to all the UI-Router services.
|
|
497
|
+
* - `Transition`: The current [[Transition]] object; information and API about the current transition, such as
|
|
498
|
+
* "to" and "from" State Parameters and transition options.
|
|
499
|
+
* - `'$transition$'`: A string alias for the `Transition` injectable
|
|
500
|
+
* - `'$state$'`: For `onEnter`/`onExit`/`onRetain`, the state being entered/exited/retained.
|
|
501
|
+
* - Other resolve tokens: A resolve can depend on another resolve, either from the same state, or from any parent state.
|
|
502
|
+
*
|
|
503
|
+
* #### Example:
|
|
504
|
+
* ```js
|
|
505
|
+
* // Injecting a resolve into another resolve
|
|
506
|
+
* resolve: [
|
|
507
|
+
* // Define a resolve 'allusers' which delegates to the UserService.list()
|
|
508
|
+
* // which returns a promise (async) for all the users
|
|
509
|
+
* { provide: 'allusers', useFactory: (UserService) => UserService.list(), deps: [UserService] },
|
|
510
|
+
*
|
|
511
|
+
* // Define a resolve 'user' which depends on the allusers resolve.
|
|
512
|
+
* // This resolve function is not called until 'allusers' is ready.
|
|
513
|
+
* { provide: 'user', (allusers, trans) => _.find(allusers, trans.params().userId, deps: ['allusers', Transition] }
|
|
514
|
+
* }
|
|
515
|
+
* ```
|
|
516
|
+
*/
|
|
517
|
+
resolve?:
|
|
518
|
+
| ResolveTypes[]
|
|
519
|
+
| {
|
|
520
|
+
[key: string]: Injectable;
|
|
521
|
+
};
|
|
522
|
+
/**
|
|
523
|
+
* Sets the resolve policy defaults for all resolves on this state
|
|
524
|
+
*
|
|
525
|
+
* This should be an [[ResolvePolicy]] object.
|
|
526
|
+
*
|
|
527
|
+
* It can contain the following optional keys/values:
|
|
528
|
+
*
|
|
529
|
+
* - `when`: (optional) defines when the resolve is fetched. Accepted values: "LAZY" or "EAGER"
|
|
530
|
+
* - `async`: (optional) if the transition waits for the resolve. Accepted values: "WAIT", "NOWAIT", {@link CustomAsyncPolicy}
|
|
531
|
+
*
|
|
532
|
+
* See [[ResolvePolicy]] for more details.
|
|
533
|
+
*/
|
|
534
|
+
resolvePolicy?: ResolvePolicy;
|
|
535
|
+
/**
|
|
536
|
+
* The url fragment for the state
|
|
537
|
+
*
|
|
538
|
+
* A URL fragment (with optional parameters) which is used to match the browser location with this state.
|
|
539
|
+
*
|
|
540
|
+
* This fragment will be appended to the parent state's URL in order to build up the overall URL for this state.
|
|
541
|
+
* See [[UrlMatcher]] for details on acceptable patterns.
|
|
542
|
+
*
|
|
543
|
+
* @examples
|
|
544
|
+
* ```js
|
|
545
|
+
*
|
|
546
|
+
* url: "/home"
|
|
547
|
+
* // Define a parameter named 'userid'
|
|
548
|
+
* url: "/users/:userid"
|
|
549
|
+
* // param 'bookid' has a custom regexp
|
|
550
|
+
* url: "/books/{bookid:[a-zA-Z_-]}"
|
|
551
|
+
* // param 'categoryid' is of type 'int'
|
|
552
|
+
* url: "/books/{categoryid:int}"
|
|
553
|
+
* // two parameters for this state
|
|
554
|
+
* url: "/books/{publishername:string}/{categoryid:int}"
|
|
555
|
+
* // Query parameters
|
|
556
|
+
* url: "/messages?before&after"
|
|
557
|
+
* // Query parameters of type 'date'
|
|
558
|
+
* url: "/messages?{before:date}&{after:date}"
|
|
559
|
+
* // Path and query parameters
|
|
560
|
+
* url: "/messages/:mailboxid?{before:date}&{after:date}"
|
|
561
|
+
* ```
|
|
562
|
+
*/
|
|
563
|
+
url?: string;
|
|
564
|
+
/**
|
|
565
|
+
* Params configuration
|
|
566
|
+
*
|
|
567
|
+
* An object which optionally configures parameters declared in the url, or defines additional non-url
|
|
568
|
+
* parameters. For each parameter being configured, add a [[ParamDeclaration]] keyed to the name of the parameter.
|
|
569
|
+
*
|
|
570
|
+
* #### Example:
|
|
571
|
+
* ```js
|
|
572
|
+
* params: {
|
|
573
|
+
* param1: {
|
|
574
|
+
* type: "int",
|
|
575
|
+
* array: true,
|
|
576
|
+
* value: []
|
|
577
|
+
* },
|
|
578
|
+
* param2: {
|
|
579
|
+
* value: "index"
|
|
580
|
+
* }
|
|
581
|
+
* }
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
584
|
+
params?: {
|
|
585
|
+
[key: string]: ParamDeclaration | any;
|
|
586
|
+
};
|
|
587
|
+
/**
|
|
588
|
+
* Named views
|
|
589
|
+
*
|
|
590
|
+
* An optional object which defines multiple views, or explicitly targets specific named ui-views.
|
|
591
|
+
*
|
|
592
|
+
* - What is a view urlConfig
|
|
593
|
+
* - What is a ui-view
|
|
594
|
+
* - Shorthand controller/template
|
|
595
|
+
* - Incompatible with ^
|
|
596
|
+
*
|
|
597
|
+
* Examples:
|
|
598
|
+
*
|
|
599
|
+
* Targets three named ui-views in the parent state's template
|
|
600
|
+
*
|
|
601
|
+
* #### Example:
|
|
602
|
+
* ```js
|
|
603
|
+
* views: {
|
|
604
|
+
* header: {
|
|
605
|
+
* controller: "headerCtrl",
|
|
606
|
+
* templateUrl: "header.html"
|
|
607
|
+
* }, body: {
|
|
608
|
+
* controller: "bodyCtrl",
|
|
609
|
+
* templateUrl: "body.html"
|
|
610
|
+
* }, footer: {
|
|
611
|
+
* controller: "footCtrl",
|
|
612
|
+
* templateUrl: "footer.html"
|
|
613
|
+
* }
|
|
614
|
+
* }
|
|
615
|
+
* ```
|
|
616
|
+
*
|
|
617
|
+
* @example
|
|
618
|
+
* ```js
|
|
619
|
+
* // Targets named ui-view="header" from ancestor state 'top''s template, and
|
|
620
|
+
* // named `ui-view="body" from parent state's template.
|
|
621
|
+
* views: {
|
|
622
|
+
* 'header@top': {
|
|
623
|
+
* controller: "msgHeaderCtrl",
|
|
624
|
+
* templateUrl: "msgHeader.html"
|
|
625
|
+
* }, 'body': {
|
|
626
|
+
* controller: "messagesCtrl",
|
|
627
|
+
* templateUrl: "messages.html"
|
|
628
|
+
* }
|
|
629
|
+
* }
|
|
630
|
+
* ```
|
|
631
|
+
*/
|
|
632
|
+
views?: {
|
|
633
|
+
[key: string]: ViewDeclaration;
|
|
634
|
+
};
|
|
635
|
+
/**
|
|
636
|
+
* An inherited property to store state data
|
|
637
|
+
*
|
|
638
|
+
* This is a spot for you to store inherited state metadata.
|
|
639
|
+
* Child states' `data` object will prototypally inherit from their parent state.
|
|
640
|
+
*
|
|
641
|
+
* This is a good spot to put metadata such as `requiresAuth`.
|
|
642
|
+
*
|
|
643
|
+
* Note: because prototypal inheritance is used, changes to parent `data` objects reflect in the child `data` objects.
|
|
644
|
+
* Care should be taken if you are using `hasOwnProperty` on the `data` object.
|
|
645
|
+
* Properties from parent objects will return false for `hasOwnProperty`.
|
|
646
|
+
*/
|
|
647
|
+
data?: any;
|
|
648
|
+
/**
|
|
649
|
+
* Synchronously or asynchronously redirects Transitions to a different state/params
|
|
650
|
+
*
|
|
651
|
+
* If this property is defined, a Transition directly to this state will be redirected based on the property's value.
|
|
652
|
+
*
|
|
653
|
+
* - If the value is a `string`, the Transition is redirected to the state named by the string.
|
|
654
|
+
*
|
|
655
|
+
* - If the property is an object with a `state` and/or `params` property,
|
|
656
|
+
* the Transition is redirected to the named `state` and/or `params`.
|
|
657
|
+
*
|
|
658
|
+
* - If the value is a [[TargetState]] the Transition is redirected to the `TargetState`
|
|
659
|
+
*
|
|
660
|
+
* - If the property is a function:
|
|
661
|
+
* - The function is called with the current [[Transition]]
|
|
662
|
+
* - The return value is processed using the previously mentioned rules.
|
|
663
|
+
* - If the return value is a promise, the promise is waited for, then the resolved async value is processed using the same rules.
|
|
664
|
+
*
|
|
665
|
+
* Note: `redirectTo` is processed as an `onStart` hook, before `LAZY` resolves.
|
|
666
|
+
* If your redirect function relies on resolve data, get the [[Transition.injector]] and get a
|
|
667
|
+
* promise for the resolve data using [[UIInjector.getAsync]].
|
|
668
|
+
*
|
|
669
|
+
* #### Example:
|
|
670
|
+
* ```js
|
|
671
|
+
* // a string
|
|
672
|
+
* .state('A', {
|
|
673
|
+
* redirectTo: 'A.B'
|
|
674
|
+
* })
|
|
675
|
+
*
|
|
676
|
+
* // a {state, params} object
|
|
677
|
+
* .state('C', {
|
|
678
|
+
* redirectTo: { state: 'C.D', params: { foo: 'index' } }
|
|
679
|
+
* })
|
|
680
|
+
*
|
|
681
|
+
* // a fn
|
|
682
|
+
* .state('E', {
|
|
683
|
+
* redirectTo: () => "A"
|
|
684
|
+
* })
|
|
685
|
+
*
|
|
686
|
+
* // a fn conditionally returning a {state, params}
|
|
687
|
+
* .state('F', {
|
|
688
|
+
* redirectTo: (trans) => {
|
|
689
|
+
* if (trans.params().foo < 10)
|
|
690
|
+
* return { state: 'F', params: { foo: 10 } };
|
|
691
|
+
* }
|
|
692
|
+
* })
|
|
693
|
+
*
|
|
694
|
+
* // a fn returning a promise for a redirect
|
|
695
|
+
* .state('G', {
|
|
696
|
+
* redirectTo: (trans) => {
|
|
697
|
+
* let svc = trans.injector().get('SomeAsyncService')
|
|
698
|
+
* let promise = svc.getAsyncRedirectTo(trans.params.foo);
|
|
699
|
+
* return promise;
|
|
700
|
+
* }
|
|
701
|
+
* })
|
|
702
|
+
*
|
|
703
|
+
* // a fn that fetches resolve data
|
|
704
|
+
* .state('G', {
|
|
705
|
+
* redirectTo: (trans) => {
|
|
706
|
+
* // getAsync tells the resolve to load
|
|
707
|
+
* let resolvePromise = trans.injector().getAsync('SomeResolve')
|
|
708
|
+
* return resolvePromise.then(resolveData => resolveData === 'login' ? 'login' : null);
|
|
709
|
+
* }
|
|
710
|
+
* })
|
|
711
|
+
* ```
|
|
712
|
+
*/
|
|
713
|
+
redirectTo?:
|
|
714
|
+
| RedirectToResult
|
|
715
|
+
| ((transition: Transition) => RedirectToResult)
|
|
716
|
+
| ((transition: Transition) => Promise<RedirectToResult>);
|
|
717
|
+
/**
|
|
718
|
+
* A state hook invoked when a state is being entered.
|
|
719
|
+
*
|
|
720
|
+
* The hook can inject global services.
|
|
721
|
+
* It can also inject `$transition$` or `$state$` (from the current transition).
|
|
722
|
+
*
|
|
723
|
+
* ### Example:
|
|
724
|
+
* ```js
|
|
725
|
+
* $stateProvider.state({
|
|
726
|
+
* name: 'mystate',
|
|
727
|
+
* onEnter: (MyService, $transition$, $state$) => {
|
|
728
|
+
* return MyService.doSomething($state$.name, $transition$.params());
|
|
729
|
+
* }
|
|
730
|
+
* });
|
|
731
|
+
* ```
|
|
732
|
+
*
|
|
733
|
+
* #### Example:`
|
|
734
|
+
* ```js
|
|
735
|
+
* $stateProvider.state({
|
|
736
|
+
* name: 'mystate',
|
|
737
|
+
* onEnter: [ 'MyService', '$transition$', '$state$', function (MyService, $transition$, $state$) {
|
|
738
|
+
* return MyService.doSomething($state$.name, $transition$.params());
|
|
739
|
+
* } ]
|
|
740
|
+
* });
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
743
|
+
onEnter?: TransitionStateHookFn | Injectable;
|
|
744
|
+
/**
|
|
745
|
+
* A state hook invoked when a state is being retained.
|
|
746
|
+
*
|
|
747
|
+
* The hook can inject global services.
|
|
748
|
+
* It can also inject `$transition$` or `$state$` (from the current transition).
|
|
749
|
+
*
|
|
750
|
+
* #### Example:
|
|
751
|
+
* ```js
|
|
752
|
+
* $stateProvider.state({
|
|
753
|
+
* name: 'mystate',
|
|
754
|
+
* onRetain: (MyService, $transition$, $state$) => {
|
|
755
|
+
* return MyService.doSomething($state$.name, $transition$.params());
|
|
756
|
+
* }
|
|
757
|
+
* });
|
|
758
|
+
* ```
|
|
759
|
+
*
|
|
760
|
+
* #### Example:`
|
|
761
|
+
* ```js
|
|
762
|
+
* $stateProvider.state({
|
|
763
|
+
* name: 'mystate',
|
|
764
|
+
* onRetain: [ 'MyService', '$transition$', '$state$', function (MyService, $transition$, $state$) {
|
|
765
|
+
* return MyService.doSomething($state$.name, $transition$.params());
|
|
766
|
+
* } ]
|
|
767
|
+
* });
|
|
768
|
+
* ```
|
|
769
|
+
*/
|
|
770
|
+
onRetain?: TransitionStateHookFn | Injectable;
|
|
771
|
+
/**
|
|
772
|
+
* A state hook invoked when a state is being exited.
|
|
773
|
+
*
|
|
774
|
+
* The hook can inject global services.
|
|
775
|
+
* It can also inject `$transition$` or `$state$` (from the current transition).
|
|
776
|
+
*
|
|
777
|
+
* ### Example:
|
|
778
|
+
* ```js
|
|
779
|
+
* $stateProvider.state({
|
|
780
|
+
* name: 'mystate',
|
|
781
|
+
* onExit: (MyService, $transition$, $state$) => {
|
|
782
|
+
* return MyService.doSomething($state$.name, $transition$.params());
|
|
783
|
+
* }
|
|
784
|
+
* });
|
|
785
|
+
* ```
|
|
786
|
+
*
|
|
787
|
+
* #### Example:`
|
|
788
|
+
* ```js
|
|
789
|
+
* $stateProvider.state({
|
|
790
|
+
* name: 'mystate',
|
|
791
|
+
* onExit: [ 'MyService', '$transition$', '$state$', function (MyService, $transition$, $state$) {
|
|
792
|
+
* return MyService.doSomething($state$.name, $transition$.params());
|
|
793
|
+
* } ]
|
|
794
|
+
* });
|
|
795
|
+
* ```
|
|
796
|
+
*/
|
|
797
|
+
onExit?: TransitionStateHookFn | Injectable;
|
|
798
|
+
/**
|
|
799
|
+
* A function used to lazy load code
|
|
800
|
+
*
|
|
801
|
+
* The `lazyLoad` function is invoked before the state is activated.
|
|
802
|
+
* The transition waits while the code is loading.
|
|
803
|
+
*
|
|
804
|
+
* The function should load the code that is required to activate the state.
|
|
805
|
+
* For example, it may load a component class, or some service code.
|
|
806
|
+
* The function must return a promise which resolves when loading is complete.
|
|
807
|
+
*
|
|
808
|
+
* For example, this code lazy loads a service before the `abc` state is activated:
|
|
809
|
+
*
|
|
810
|
+
* ```
|
|
811
|
+
* .state('abc', {
|
|
812
|
+
* lazyLoad: (transition, state) => import('./abcService')
|
|
813
|
+
* }
|
|
814
|
+
* ```
|
|
815
|
+
*
|
|
816
|
+
* The `abcService` file is imported and loaded
|
|
817
|
+
* (it is assumed that the `abcService` file knows how to register itself as a service).
|
|
818
|
+
*
|
|
819
|
+
* #### Lifecycle
|
|
820
|
+
*
|
|
821
|
+
* - The `lazyLoad` function is invoked if a transition is going to enter the state.
|
|
822
|
+
* - The function is invoked before the transition starts (using an `onBefore` transition hook).
|
|
823
|
+
* - The function is only invoked once; while the `lazyLoad` function is loading code, it will not be invoked again.
|
|
824
|
+
* For example, if the user double clicks a ui-sref, `lazyLoad` is only invoked once even though there were two transition attempts.
|
|
825
|
+
* Instead, the existing lazy load promise is re-used.
|
|
826
|
+
* - When the promise resolves successfully, the `lazyLoad` property is deleted from the state declaration.
|
|
827
|
+
* - If the promise resolves to a [[LazyLoadResult]] which has an array of `states`, those states are registered.
|
|
828
|
+
* - The original transition is retried (this time without the `lazyLoad` property present).
|
|
829
|
+
*
|
|
830
|
+
* - If the `lazyLoad` function fails, then the transition also fails.
|
|
831
|
+
* The failed transition (and the `lazyLoad` function) could potentially be retried by the user.
|
|
832
|
+
*
|
|
833
|
+
* ### Lazy loading state definitions (Future States)
|
|
834
|
+
*
|
|
835
|
+
* State definitions can also be lazy loaded.
|
|
836
|
+
* This might be desirable when building large, multi-module applications.
|
|
837
|
+
*
|
|
838
|
+
* To lazy load state definitions, a Future State should be registered as a placeholder.
|
|
839
|
+
* When the state definitions are lazy loaded, the Future State is deregistered.
|
|
840
|
+
*
|
|
841
|
+
* A future state can act as a placeholder for a single state, or for an entire module of states and substates.
|
|
842
|
+
* A future state should have:
|
|
843
|
+
*
|
|
844
|
+
* - A `name` which ends in `.**`.
|
|
845
|
+
* A future state's `name` property acts as a wildcard [[Glob]].
|
|
846
|
+
* It matches any state name that starts with the `name` (including child states that are not yet loaded).
|
|
847
|
+
* - A `url` prefix.
|
|
848
|
+
* A future state's `url` property acts as a wildcard.
|
|
849
|
+
* UI-Router matches all paths that begin with the `url`.
|
|
850
|
+
* It effectively appends `.*` to the internal regular expression.
|
|
851
|
+
* When the prefix matches, the future state will begin loading.
|
|
852
|
+
* - A `lazyLoad` function.
|
|
853
|
+
* This function should should return a Promise to lazy load the code for one or more [[StateDeclaration]] objects.
|
|
854
|
+
* It should return a [[LazyLoadResult]].
|
|
855
|
+
* Generally, one of the lazy loaded states should have the same name as the future state.
|
|
856
|
+
* The new state will then **replace the future state placeholder** in the registry.
|
|
857
|
+
*
|
|
858
|
+
* ### Additional resources
|
|
859
|
+
*
|
|
860
|
+
* For in depth information on lazy loading and Future States, see the [Lazy Loading Guide](https://ui-router.github.io/guides/lazyload).
|
|
861
|
+
*
|
|
862
|
+
* #### Example: states.js
|
|
863
|
+
* ```js
|
|
864
|
+
*
|
|
865
|
+
* // This child state is a lazy loaded future state
|
|
866
|
+
* // The `lazyLoad` function loads the final state definition
|
|
867
|
+
* {
|
|
868
|
+
* name: 'parent.**',
|
|
869
|
+
* url: '/parent',
|
|
870
|
+
* lazyLoad: () => import('./lazy.states.js')
|
|
871
|
+
* }
|
|
872
|
+
* ```
|
|
873
|
+
*
|
|
874
|
+
* #### Example: lazy.states.js
|
|
875
|
+
*
|
|
876
|
+
* This file is lazy loaded. It exports an array of states.
|
|
877
|
+
*
|
|
878
|
+
* ```js
|
|
879
|
+
* import {ChildComponent} from "./child.component.js";
|
|
880
|
+
* import {ParentComponent} from "./parent.component.js";
|
|
881
|
+
*
|
|
882
|
+
* // This fully defined state replaces the future state
|
|
883
|
+
* let parentState = {
|
|
884
|
+
* // the name should match the future state
|
|
885
|
+
* name: 'parent',
|
|
886
|
+
* url: '/parent/:parentId',
|
|
887
|
+
* component: ParentComponent,
|
|
888
|
+
* resolve: {
|
|
889
|
+
* parentData: ($transition$, ParentService) =>
|
|
890
|
+
* ParentService.get($transition$.params().parentId)
|
|
891
|
+
* }
|
|
892
|
+
* }
|
|
893
|
+
*
|
|
894
|
+
* let childState = {
|
|
895
|
+
* name: 'parent.child',
|
|
896
|
+
* url: '/child/:childId',
|
|
897
|
+
* params: {
|
|
898
|
+
* childId: "default"
|
|
899
|
+
* },
|
|
900
|
+
* resolve: {
|
|
901
|
+
* childData: ($transition$, ChildService) =>
|
|
902
|
+
* ChildService.get($transition$.params().childId)
|
|
903
|
+
* }
|
|
904
|
+
* };
|
|
905
|
+
*
|
|
906
|
+
* // This array of states will be registered by the lazyLoad hook
|
|
907
|
+
* let lazyLoadResults = {
|
|
908
|
+
* states: [ parentState, childState ]
|
|
909
|
+
* };
|
|
910
|
+
*
|
|
911
|
+
* export default lazyLoadResults;
|
|
912
|
+
* ```
|
|
913
|
+
*
|
|
914
|
+
* @param transition the [[Transition]] that is activating the future state
|
|
915
|
+
* @param state the [[StateDeclaration]] that the `lazyLoad` function is declared on
|
|
916
|
+
* @return a Promise to load the states.
|
|
917
|
+
* Optionally, if the promise resolves to a [[LazyLoadResult]],
|
|
918
|
+
* the states will be registered with the [[StateRegistry]].
|
|
919
|
+
*/
|
|
920
|
+
lazyLoad?: (
|
|
921
|
+
transition: Transition,
|
|
922
|
+
state: StateDeclaration,
|
|
923
|
+
) => Promise<LazyLoadResult>;
|
|
924
|
+
/**
|
|
925
|
+
* Marks all the state's parameters as `dynamic`.
|
|
926
|
+
*
|
|
927
|
+
* All parameters on the state will use this value for `dynamic` as a default.
|
|
928
|
+
* Individual parameters may override this default using [[ParamDeclaration.dynamic]] in the [[params]] block.
|
|
929
|
+
*
|
|
930
|
+
* Note: this value overrides the `dynamic` value on a custom parameter type ([[ParamTypeDefinition.dynamic]]).
|
|
931
|
+
*/
|
|
932
|
+
dynamic?: boolean;
|
|
933
|
+
/**
|
|
934
|
+
* Marks all query parameters as [[ParamDeclaration.dynamic]]
|
|
935
|
+
*
|
|
936
|
+
* @deprecated use either [[dynamic]] or [[ParamDeclaration.dynamic]]
|
|
937
|
+
*/
|
|
938
|
+
reloadOnSearch?: boolean;
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* The return type of a [[StateDeclaration.lazyLoad]] function
|
|
942
|
+
*
|
|
943
|
+
* If your state has a `lazyLoad` function, it should return a promise.
|
|
944
|
+
* If promise resolves to an object matching this interface, then the `states` array
|
|
945
|
+
* of [[StateDeclaration]] objects will be automatically registered.
|
|
946
|
+
*/
|
|
947
|
+
export interface LazyLoadResult {
|
|
948
|
+
states?: StateDeclaration[];
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* An options object for [[StateService.href]]
|
|
952
|
+
*/
|
|
953
|
+
export interface HrefOptions {
|
|
954
|
+
/**
|
|
955
|
+
* Defines what state to be "relative from"
|
|
956
|
+
*
|
|
957
|
+
* When a relative path is found (e.g `^` or `.bar`), defines which state to be relative from.
|
|
958
|
+
*/
|
|
959
|
+
relative?: StateOrName;
|
|
960
|
+
/**
|
|
961
|
+
* If true, and if there is no url associated with the state provided in the
|
|
962
|
+
* first parameter, then the constructed href url will be built from the first
|
|
963
|
+
* ancestor which has a url.
|
|
964
|
+
*/
|
|
965
|
+
lossy?: boolean;
|
|
966
|
+
/**
|
|
967
|
+
* If `true` will inherit parameters from the current parameter values.
|
|
968
|
+
*/
|
|
969
|
+
inherit?: boolean;
|
|
970
|
+
/**
|
|
971
|
+
* If true will generate an absolute url, e.g. `http://www.example.com/fullurl`.
|
|
972
|
+
*/
|
|
973
|
+
absolute?: boolean;
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Either a [[StateDeclaration]] or an ES6 class that implements [[StateDeclaration]]
|
|
977
|
+
* The ES6 class constructor should have no arguments.
|
|
978
|
+
*/
|
|
979
|
+
export type _StateDeclaration =
|
|
980
|
+
| StateDeclaration
|
|
981
|
+
| {
|
|
982
|
+
new (): StateDeclaration;
|
|
983
|
+
};
|