From c74a438f0c9f6cf110ecf95a79f217b432a22831 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Tue, 30 Aug 2016 15:57:24 -0700 Subject: [PATCH] docs(router): fix up the exampesd --- modules/@angular/router/src/interfaces.ts | 52 +++++++++++++++++-- modules/@angular/router/src/router.ts | 4 +- modules/@angular/router/src/router_state.ts | 8 ++- .../router/testing/router_testing_module.ts | 2 +- tools/public_api_guard/router/index.d.ts | 4 +- 5 files changed, 59 insertions(+), 11 deletions(-) diff --git a/modules/@angular/router/src/interfaces.ts b/modules/@angular/router/src/interfaces.ts index 6135ec8903..a6fcf065f7 100644 --- a/modules/@angular/router/src/interfaces.ts +++ b/modules/@angular/router/src/interfaces.ts @@ -18,6 +18,13 @@ import {ActivatedRouteSnapshot, RouterStateSnapshot} from './router_state'; * ### Example * * ``` + * class UserToken {} + * class Permissions { + * canActivate(user: UserToken, id: string): boolean { + * return true; + * } + * } + * * @Injectable() * class CanActivateTeam implements CanActivate { * constructor(private permissions: Permissions, private currentUser: UserToken) {} @@ -40,8 +47,9 @@ import {ActivatedRouteSnapshot, RouterStateSnapshot} from './router_state'; * } * ]) * ], - * providers: [CanActivateTeam] + * providers: [CanActivateTeam, UserToken, Permissions] * }) + * class AppModule {} * ``` * * You can also provide a function with the same signature instead of the class: @@ -64,6 +72,7 @@ import {ActivatedRouteSnapshot, RouterStateSnapshot} from './router_state'; * } * ] * }) + * class AppModule {} * ``` * * @stable @@ -79,6 +88,13 @@ export interface CanActivate { * ### Example * * ``` + * class UserToken {} + * class Permissions { + * canActivate(user: UserToken, id: string): boolean { + * return true; + * } + * } + * * @Injectable() * class CanActivateTeam implements CanActivate { * constructor(private permissions: Permissions, private currentUser: UserToken) {} @@ -106,8 +122,9 @@ export interface CanActivate { * } * ]) * ], - * providers: [CanActivateTeam] + * providers: [CanActivateTeam, UserToken, Permissions] * }) + * class AppModule {} * ``` * * You can also provide a function with the same signature instead of the class: @@ -135,6 +152,7 @@ export interface CanActivate { * } * ] * }) + * class AppModule {} * ``` * * @stable @@ -151,6 +169,13 @@ export interface CanActivateChild { * ### Example * * ``` + * class UserToken {} + * class Permissions { + * canDeactivate(user: UserToken, id: string): boolean { + * return true; + * } + * } + * * @Injectable() * class CanDeactivateTeam implements CanDeactivate { * constructor(private permissions: Permissions, private currentUser: UserToken) {} @@ -174,8 +199,9 @@ export interface CanActivateChild { * } * ]) * ], - * providers: [CanDeactivateTeam] + * providers: [CanDeactivateTeam, UserToken, Permissions] * }) + * class AppModule {} * ``` * * You can also provide a function with the same signature instead of the class: @@ -198,6 +224,7 @@ export interface CanActivateChild { * } * ] * }) + * class AppModule {} * ``` * * @stable @@ -213,6 +240,12 @@ export interface CanDeactivate { * ### Example * * ``` + * class Backend { + * fetchTeam(id: string) { + * return 'someTeam'; + * } + * } + * * @Injectable() * class TeamResolver implements Resolve { * constructor(private backend: Backend) {} @@ -239,6 +272,7 @@ export interface CanDeactivate { * ], * providers: [TeamResolver] * }) + * class AppModule {} * ``` * * You can also provide a function with the same signature instead of the class. @@ -263,6 +297,7 @@ export interface CanDeactivate { * } * ] * }) + * class AppModule {} * ``` * @stable */ @@ -278,6 +313,13 @@ export interface Resolve { * ### Example * * ``` + * class UserToken {} + * class Permissions { + * canLoadChildren(user: UserToken, id: string): boolean { + * return true; + * } + * } + * * @Injectable() * class CanLoadTeamSection implements CanLoad { * constructor(private permissions: Permissions, private currentUser: UserToken) {} @@ -300,8 +342,9 @@ export interface Resolve { * } * ]) * ], - * providers: [CanLoadTeamSection] + * providers: [CanLoadTeamSection, UserToken, Permissions] * }) + * class AppModule {} * ``` * * You can also provide a function with the same signature instead of the class: @@ -325,6 +368,7 @@ export interface Resolve { * } * ] * }) + * class AppModule {} * ``` * * @stable diff --git a/modules/@angular/router/src/router.ts b/modules/@angular/router/src/router.ts index bd456a160c..c754c550f6 100644 --- a/modules/@angular/router/src/router.ts +++ b/modules/@angular/router/src/router.ts @@ -36,7 +36,7 @@ import {TreeNode} from './utils/tree'; declare var Zone: any; /** - * @experimental + * @stable */ export interface NavigationExtras { /** @@ -235,7 +235,7 @@ export class Router { /** * Indicates if at least one navigation happened. * - * @experimental + * @stable */ navigated: boolean = false; diff --git a/modules/@angular/router/src/router_state.ts b/modules/@angular/router/src/router_state.ts index 69090fe619..0b70de9161 100644 --- a/modules/@angular/router/src/router_state.ts +++ b/modules/@angular/router/src/router_state.ts @@ -23,11 +23,12 @@ import {Tree, TreeNode} from './utils/tree'; * ### Usage * * ``` + * @Component({template:''}) * class MyComponent { * constructor(router: Router) { * const state = router.routerState; - * const id: Observable = state.firstChild(state.root).params.map(p => p.id); - * const isDebug: Observable = state.queryParams.map(q => q.debug); + * const id: Observable = state.root.firstChild.params.map(p => p.id); + * const isDebug: Observable = state.root.queryParams.map(q => q.debug); * } * } * ``` @@ -79,6 +80,7 @@ export function createEmptyStateSnapshot( * ### Usage * * ``` + * @Component({template:''}) * class MyComponent { * constructor(route: ActivatedRoute) { * const id: Observable = route.params.map(p => p.id); @@ -153,6 +155,7 @@ export class InheritedResolve { * ### Usage * * ``` + * @Component({template:''}) * class MyComponent { * constructor(route: ActivatedRoute) { * const id: string = route.snapshot.params.id; @@ -218,6 +221,7 @@ export class ActivatedRouteSnapshot { * ### Usage * * ``` + * @Component({template:''}) * class MyComponent { * constructor(router: Router) { * const snapshot = router.routerState.snapshot; diff --git a/modules/@angular/router/testing/router_testing_module.ts b/modules/@angular/router/testing/router_testing_module.ts index bc2a74a415..8bd9f37bdc 100644 --- a/modules/@angular/router/testing/router_testing_module.ts +++ b/modules/@angular/router/testing/router_testing_module.ts @@ -37,7 +37,7 @@ export class SpyNgModuleFactoryLoader implements NgModuleFactoryLoader { /** * Router setup factory function used for testing. * - * @experimental + * @stable */ export function setupTestingRouter( urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, diff --git a/tools/public_api_guard/router/index.d.ts b/tools/public_api_guard/router/index.d.ts index 21923cee94..d3f7d122e0 100644 --- a/tools/public_api_guard/router/index.d.ts +++ b/tools/public_api_guard/router/index.d.ts @@ -110,7 +110,7 @@ export declare class NavigationError { toString(): string; } -/** @experimental */ +/** @stable */ export interface NavigationExtras { fragment?: string; preserveFragment?: boolean; @@ -172,7 +172,7 @@ export declare class Router { config: Routes; errorHandler: ErrorHandler; events: Observable; - /** @experimental */ navigated: boolean; + /** @stable */ navigated: boolean; routerState: RouterState; url: string; constructor(rootComponentType: Type, urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, injector: Injector, loader: NgModuleFactoryLoader, compiler: Compiler, config: Routes);