2
2
/** */
3
3
4
4
import { StateDeclaration , _ViewDeclaration , Transition , HookResult } from '@uirouter/core' ;
5
- import { Type , Component } from '@angular/core' ;
5
+ import { Component , Type } from '@angular/core' ;
6
6
import { ModuleTypeCallback } from './lazyLoad/lazyLoadNgModule' ;
7
7
8
8
/**
@@ -286,6 +286,89 @@ export interface Ng2ViewDeclaration extends _ViewDeclaration {
286
286
bindings ?: { [ key : string ] : string } ;
287
287
}
288
288
289
+ export interface UiOnParamsChanged {
290
+ /**
291
+ * A UI-Router view has an Angular `Component` (see [[Ng2ViewDeclaration.component]]).
292
+ * The `Component` may define component-level hooks which UI-Router will call at the appropriate times.
293
+ * These callbacks are similar to Transition Hooks ([[IHookRegistry]]), but are only called if the view/component is currently active.
294
+ *
295
+ * The uiOnParamsChanged callback is called when parameter values change.
296
+ *
297
+ * This callback is used to respond dynamic parameter values changing.
298
+ * It is called when a transition changed one or more dynamic parameter values,
299
+ * and the routed component was not destroyed.
300
+ *
301
+ * It receives two parameters:
302
+ *
303
+ * - An object with (only) changed parameter values.
304
+ * The keys are the parameter names and the values are the new parameter values.
305
+ * - The [[Transition]] which changed the parameter values.
306
+ *
307
+ * #### Example:
308
+ * ```js
309
+ * @Component ({
310
+ * template: '<input type="text">'
311
+ * })
312
+ * class MyComponent {
313
+ * uiOnParamsChanged(newParams: { [paramName: string]: any }, trans: Transition) {
314
+ * Object.keys(newParams).forEach(paramName => {
315
+ * console.log(`${paramName} changed to ${newParams[paramName]}`)
316
+ * });
317
+ * }
318
+ * }
319
+ * ```
320
+ */
321
+ uiOnParamsChanged ( newParams : { [ paramName : string ] : any } , trans ?: Transition ) : void ;
322
+ }
323
+
324
+ export interface UiOnExit {
325
+ /**
326
+ * A UI-Router view has an Angular `Component` (see [[Ng2ViewDeclaration.component]]).
327
+ * The `Component` may define component-level hooks which UI-Router will call at the appropriate times.
328
+ * These callbacks are similar to Transition Hooks ([[IHookRegistry]]), but are only called if the view/component is currently active.
329
+ *
330
+ * The uiCanExit callback is called when the routed component's state is about to be exited.
331
+ *
332
+ * The callback can be used to cancel or alter the new Transition that would otherwise exit the component's state.
333
+ *
334
+ * This callback is used to inform a view that it is about to be exited, due to a new [[Transition]].
335
+ * The callback can ask for user confirmation, and cancel or alter the new Transition. The callback should
336
+ * return a value, or a promise for a value. If a promise is returned, the new Transition waits until the
337
+ * promise settles.
338
+ *
339
+ * Called when:
340
+ * - The component is still active inside a `ui-view`
341
+ * - A new Transition is about to run
342
+ * - The new Transition will exit the view's state
343
+ *
344
+ * Called with:
345
+ * - The `Transition` that is about to exit the component's state
346
+ *
347
+ * #### Example:
348
+ * ```js
349
+ * @Component ({
350
+ * template: '<input type="text">'
351
+ * })
352
+ * class MyComponent {
353
+ * dirty = true;
354
+ *
355
+ * constructor(public confirmService: confirmService) {
356
+ *
357
+ * }
358
+ *
359
+ * uiCanExit(newTransition: Transition) {
360
+ * if (this.dirty && newTransition.to() !== 'logout') {
361
+ * return this.confirmService.confirm("Exit without saving changes?");
362
+ * }
363
+ * }
364
+ * }
365
+ * ```
366
+ *
367
+ * @return a hook result which may cancel or alter the pending Transition (see [[HookResult]])
368
+ */
369
+ uiCanExit ( newTransition ?: Transition ) : HookResult ;
370
+ }
371
+
289
372
/**
290
373
* The shape of a controller for a view (and/or component), defining the controller callbacks.
291
374
*
@@ -294,6 +377,8 @@ export interface Ng2ViewDeclaration extends _ViewDeclaration {
294
377
* These callbacks are similar to Transition Hooks ([[IHookRegistry]]), but are only called if the view/component is currently active.
295
378
*
296
379
* This interface defines the UI-Router component callbacks.
380
+ *
381
+ * @deprecated This interface has been replaced by UiOnExit and UiOnParamsChanged.
297
382
*/
298
383
export interface Ng2Component extends Component {
299
384
/**
0 commit comments