|
2 | 2 | /** */
|
3 | 3 |
|
4 | 4 | import { StateDeclaration, _ViewDeclaration, Transition, HookResult } from "ui-router-core";
|
5 |
| -import { Type } from "@angular/core"; |
| 5 | +import { Type, Component } from "@angular/core"; |
6 | 6 | import { NgModuleToLoad } from "./lazyLoad/lazyLoadNgModule";
|
7 | 7 |
|
8 | 8 | /**
|
@@ -293,111 +293,91 @@ export interface Ng2ViewDeclaration extends _ViewDeclaration {
|
293 | 293 | *
|
294 | 294 | * When using a [[component]] declaration (`component: MyComponent`), each input binding for the component is supplied
|
295 | 295 | * data from a resolve of the same name, by default. You may supply data from a different resolve name by mapping it here.
|
| 296 | + * This might be useful if you want to reuse the same resolve value with various components with different input binding names. |
296 | 297 | *
|
297 | 298 | * Each key in this object is the name of one of the component's input bindings.
|
298 | 299 | * Each value is the name of the resolve that should be provided to that binding.
|
299 | 300 | *
|
300 |
| - * Any component bindings that are omitted from this map get the default behavior of mapping to a resolve of the |
301 |
| - * same name. |
| 301 | + * Any component bindings that are omitted from this map get the default behavior of mapping to a resolve of the * same name. |
302 | 302 | *
|
303 | 303 | * #### Example:
|
304 | 304 | * ```js
|
305 |
| - * $stateProvider.state('foo', { |
306 |
| - * resolve: { |
307 |
| - * foo: function(FooService) { return FooService.get(); }, |
308 |
| - * bar: function(BarService) { return BarService.get(); } |
309 |
| - * }, |
310 |
| - * component: 'Baz', |
311 |
| - * // The component's `baz` binding gets data from the `bar` resolve |
312 |
| - * // The component's `foo` binding gets data from the `foo` resolve (default behavior) |
| 305 | + * export const fooState = { |
| 306 | + * name: 'foo', |
| 307 | + * component: MyComponent, |
| 308 | + * resolve: [ |
| 309 | + * { token: 'users', deps: [UserService], resolveFn: getUsers } |
| 310 | + * ], |
313 | 311 | * bindings: {
|
314 |
| - * baz: 'bar' |
| 312 | + * resolveData: 'users' |
315 | 313 | * }
|
316 |
| - * }); |
| 314 | + * } |
317 | 315 | *
|
318 |
| - * app.component('Baz', { |
319 |
| - * templateUrl: 'baz.html', |
320 |
| - * controller: 'BazController', |
321 |
| - * bindings: { |
322 |
| - * foo: '<', // foo binding |
323 |
| - * baz: '<' // baz binding |
324 |
| - * } |
325 |
| - * }); |
| 316 | + * export function getUsers(userservice) { |
| 317 | + * return userservice.getUsers(); |
| 318 | + * } |
| 319 | + * |
| 320 | + * @Component() { |
| 321 | + * } |
| 322 | + * class MyComponent { |
| 323 | + * @Input() resolveData; |
| 324 | + * constructor() { } |
| 325 | + * } |
326 | 326 | * ```
|
327 | 327 | *
|
328 | 328 | */
|
329 | 329 | bindings?: { [key: string]: string };
|
330 | 330 | }
|
331 | 331 |
|
332 | 332 | /**
|
333 |
| - * @hidden |
334 |
| - * |
335 | 333 | * The shape of a controller for a view (and/or component), defining the controller callbacks.
|
336 | 334 | *
|
337 |
| - * A view in UI-Router is comprised of either a `component` ([[Ng2ViewDeclaration.component]]) or a combination of a |
338 |
| - * `template` (or `templateProvider`) and a `controller` (or `controllerProvider`). |
339 |
| - * |
340 |
| - * The `controller` object (or the `component`'s controller object) can define component-level controller callbacks, |
341 |
| - * which UI-Router will call at the appropriate times. These callbacks are similar to Transition Hooks |
342 |
| - * ([[IHookRegistry]]), but are only called if the view is currently active. |
| 335 | + * A UI-Router view has an Angular `Component` (see [[Ng2ViewDeclaration.component]]). |
| 336 | + * The `Component` may define component-level hooks which UI-Router will call at the appropriate times. |
| 337 | + * These callbacks are similar to Transition Hooks ([[IHookRegistry]]), but are only called if the view/component is currently active. |
343 | 338 | *
|
344 | 339 | * This interface defines the UI-Router component callbacks.
|
345 |
| - * |
346 |
| - * TODO: this should extend the ng2 Component interface |
347 | 340 | */
|
348 |
| -export interface Ng2Component { |
| 341 | +export interface Ng2Component extends Component { |
349 | 342 | /**
|
350 |
| - * This callback is called when parameter values have changed. |
| 343 | + * This callback is called when the a routed component's state is about to be exited. |
351 | 344 | *
|
352 |
| - * This callback can be used to respond to changing parameter values in the current state, or in parent/child states. |
353 |
| - * This callback is especially handy when using dynamic parameters ([[ParamDeclaration.dynamic]]) |
354 |
| - * |
355 |
| - * Called when: |
356 |
| - * - The view is still active |
357 |
| - * - A new transition has completed successfully |
358 |
| - * - The state for the view (controller) was not reloaded |
359 |
| - * - At least one parameter value was changed |
360 |
| - * |
361 |
| - * Called with: |
362 |
| - * @param newValues an object containing the changed parameter values |
363 |
| - * @param $transition$ the new Transition which triggered this callback |
364 |
| - * |
365 |
| - * @example: |
366 |
| - * ```js |
367 |
| - * |
368 |
| - * angular.module('foo').controller('FancyCtrl', function() { |
369 |
| - * this.uiOnParamsChanged = function(newParams) { |
370 |
| - * console.log("new params: ", newParams); |
371 |
| - * } |
372 |
| - * }); |
373 |
| - * ``` |
374 |
| - */ |
375 |
| - uiOnParamsChanged(newValues: any, $transition$: Transition): void; |
376 |
| - |
377 |
| - /** |
378 |
| - * This callback is called when the view's state is about to be exited. |
| 345 | + * The callback can be used to cancel or alter the new Transition that would otherwise exit the component's state. |
379 | 346 | *
|
380 | 347 | * This callback is used to inform a view that it is about to be exited, due to a new [[Transition]].
|
381 | 348 | * The callback can ask for user confirmation, and cancel or alter the new Transition. The callback should
|
382 | 349 | * return a value, or a promise for a value. If a promise is returned, the new Transition waits until the
|
383 | 350 | * promise settles.
|
384 | 351 | *
|
385 |
| - * |
386 | 352 | * Called when:
|
387 |
| - * - The view is still active |
| 353 | + * - The component is still active inside a `ui-view` |
388 | 354 | * - A new Transition is about to run
|
389 | 355 | * - The new Transition will exit the view's state
|
390 | 356 | *
|
391 | 357 | * Called with:
|
392 |
| - * - This callback is injected in the new Transition's context |
| 358 | + * - The `Transition` that is about to exit the component's state |
393 | 359 | *
|
394 |
| - * Relevant return Values: |
395 |
| - * - `false`: The transition is cancelled. |
396 |
| - * - A rejected promise: The transition is cancelled. |
397 |
| - * - [[TargetState]]: The transition is redirected to the new target state. |
398 |
| - * - Anything else: the transition will continue normally (the state and view will be deactivated) |
| 360 | + * #### Example: |
| 361 | + * ```js |
| 362 | + * @Component({ |
| 363 | + * template: '<input type="text">' |
| 364 | + * }) |
| 365 | + * class MyComponent { |
| 366 | + * dirty = true; |
| 367 | + * |
| 368 | + * constructor(public confirmService: confirmService) { |
| 369 | + * |
| 370 | + * } |
| 371 | + * |
| 372 | + * uiCanExit(newTransition: Transition) { |
| 373 | + * if (this.dirty && newTransition.to() !== 'logout') { |
| 374 | + * return this.confirmService.confirm("Exit without saving changes?"); |
| 375 | + * } |
| 376 | + * } |
| 377 | + * } |
| 378 | + * ``` |
399 | 379 | *
|
400 |
| - * @return a value, or a promise for a value. |
| 380 | + * @return a hook result which may cancel or alter the pending Transition (see [[HookResult]]) |
401 | 381 | */
|
402 |
| - uiCanExit(): HookResult; |
| 382 | + uiCanExit(newTransition?: Transition): HookResult; |
403 | 383 | }
|
0 commit comments