docs(router): fix up the exampesd

This commit is contained in:
vsavkin 2016-08-30 15:57:24 -07:00 committed by Victor Berchet
parent c350ba29f6
commit c74a438f0c
5 changed files with 59 additions and 11 deletions

View File

@ -18,6 +18,13 @@ import {ActivatedRouteSnapshot, RouterStateSnapshot} from './router_state';
* ### Example * ### Example
* *
* ``` * ```
* class UserToken {}
* class Permissions {
* canActivate(user: UserToken, id: string): boolean {
* return true;
* }
* }
*
* @Injectable() * @Injectable()
* class CanActivateTeam implements CanActivate { * class CanActivateTeam implements CanActivate {
* constructor(private permissions: Permissions, private currentUser: UserToken) {} * 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: * 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 * @stable
@ -79,6 +88,13 @@ export interface CanActivate {
* ### Example * ### Example
* *
* ``` * ```
* class UserToken {}
* class Permissions {
* canActivate(user: UserToken, id: string): boolean {
* return true;
* }
* }
*
* @Injectable() * @Injectable()
* class CanActivateTeam implements CanActivate { * class CanActivateTeam implements CanActivate {
* constructor(private permissions: Permissions, private currentUser: UserToken) {} * 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: * You can also provide a function with the same signature instead of the class:
@ -135,6 +152,7 @@ export interface CanActivate {
* } * }
* ] * ]
* }) * })
* class AppModule {}
* ``` * ```
* *
* @stable * @stable
@ -151,6 +169,13 @@ export interface CanActivateChild {
* ### Example * ### Example
* *
* ``` * ```
* class UserToken {}
* class Permissions {
* canDeactivate(user: UserToken, id: string): boolean {
* return true;
* }
* }
*
* @Injectable() * @Injectable()
* class CanDeactivateTeam implements CanDeactivate<TeamComponent> { * class CanDeactivateTeam implements CanDeactivate<TeamComponent> {
* constructor(private permissions: Permissions, private currentUser: UserToken) {} * 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: * You can also provide a function with the same signature instead of the class:
@ -198,6 +224,7 @@ export interface CanActivateChild {
* } * }
* ] * ]
* }) * })
* class AppModule {}
* ``` * ```
* *
* @stable * @stable
@ -213,6 +240,12 @@ export interface CanDeactivate<T> {
* ### Example * ### Example
* *
* ``` * ```
* class Backend {
* fetchTeam(id: string) {
* return 'someTeam';
* }
* }
*
* @Injectable() * @Injectable()
* class TeamResolver implements Resolve<Team> { * class TeamResolver implements Resolve<Team> {
* constructor(private backend: Backend) {} * constructor(private backend: Backend) {}
@ -239,6 +272,7 @@ export interface CanDeactivate<T> {
* ], * ],
* providers: [TeamResolver] * providers: [TeamResolver]
* }) * })
* class AppModule {}
* ``` * ```
* *
* You can also provide a function with the same signature instead of the class. * You can also provide a function with the same signature instead of the class.
@ -263,6 +297,7 @@ export interface CanDeactivate<T> {
* } * }
* ] * ]
* }) * })
* class AppModule {}
* ``` * ```
* @stable * @stable
*/ */
@ -278,6 +313,13 @@ export interface Resolve<T> {
* ### Example * ### Example
* *
* ``` * ```
* class UserToken {}
* class Permissions {
* canLoadChildren(user: UserToken, id: string): boolean {
* return true;
* }
* }
*
* @Injectable() * @Injectable()
* class CanLoadTeamSection implements CanLoad { * class CanLoadTeamSection implements CanLoad {
* constructor(private permissions: Permissions, private currentUser: UserToken) {} * constructor(private permissions: Permissions, private currentUser: UserToken) {}
@ -300,8 +342,9 @@ export interface Resolve<T> {
* } * }
* ]) * ])
* ], * ],
* providers: [CanLoadTeamSection] * providers: [CanLoadTeamSection, UserToken, Permissions]
* }) * })
* class AppModule {}
* ``` * ```
* *
* You can also provide a function with the same signature instead of the class: * You can also provide a function with the same signature instead of the class:
@ -325,6 +368,7 @@ export interface Resolve<T> {
* } * }
* ] * ]
* }) * })
* class AppModule {}
* ``` * ```
* *
* @stable * @stable

View File

@ -36,7 +36,7 @@ import {TreeNode} from './utils/tree';
declare var Zone: any; declare var Zone: any;
/** /**
* @experimental * @stable
*/ */
export interface NavigationExtras { export interface NavigationExtras {
/** /**
@ -235,7 +235,7 @@ export class Router {
/** /**
* Indicates if at least one navigation happened. * Indicates if at least one navigation happened.
* *
* @experimental * @stable
*/ */
navigated: boolean = false; navigated: boolean = false;

View File

@ -23,11 +23,12 @@ import {Tree, TreeNode} from './utils/tree';
* ### Usage * ### Usage
* *
* ``` * ```
* @Component({template:''})
* class MyComponent { * class MyComponent {
* constructor(router: Router) { * constructor(router: Router) {
* const state = router.routerState; * const state = router.routerState;
* const id: Observable<string> = state.firstChild(state.root).params.map(p => p.id); * const id: Observable<string> = state.root.firstChild.params.map(p => p.id);
* const isDebug: Observable<string> = state.queryParams.map(q => q.debug); * const isDebug: Observable<string> = state.root.queryParams.map(q => q.debug);
* } * }
* } * }
* ``` * ```
@ -79,6 +80,7 @@ export function createEmptyStateSnapshot(
* ### Usage * ### Usage
* *
* ``` * ```
* @Component({template:''})
* class MyComponent { * class MyComponent {
* constructor(route: ActivatedRoute) { * constructor(route: ActivatedRoute) {
* const id: Observable<string> = route.params.map(p => p.id); * const id: Observable<string> = route.params.map(p => p.id);
@ -153,6 +155,7 @@ export class InheritedResolve {
* ### Usage * ### Usage
* *
* ``` * ```
* @Component({template:''})
* class MyComponent { * class MyComponent {
* constructor(route: ActivatedRoute) { * constructor(route: ActivatedRoute) {
* const id: string = route.snapshot.params.id; * const id: string = route.snapshot.params.id;
@ -218,6 +221,7 @@ export class ActivatedRouteSnapshot {
* ### Usage * ### Usage
* *
* ``` * ```
* @Component({template:''})
* class MyComponent { * class MyComponent {
* constructor(router: Router) { * constructor(router: Router) {
* const snapshot = router.routerState.snapshot; * const snapshot = router.routerState.snapshot;

View File

@ -37,7 +37,7 @@ export class SpyNgModuleFactoryLoader implements NgModuleFactoryLoader {
/** /**
* Router setup factory function used for testing. * Router setup factory function used for testing.
* *
* @experimental * @stable
*/ */
export function setupTestingRouter( export function setupTestingRouter(
urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location,

View File

@ -110,7 +110,7 @@ export declare class NavigationError {
toString(): string; toString(): string;
} }
/** @experimental */ /** @stable */
export interface NavigationExtras { export interface NavigationExtras {
fragment?: string; fragment?: string;
preserveFragment?: boolean; preserveFragment?: boolean;
@ -172,7 +172,7 @@ export declare class Router {
config: Routes; config: Routes;
errorHandler: ErrorHandler; errorHandler: ErrorHandler;
events: Observable<Event>; events: Observable<Event>;
/** @experimental */ navigated: boolean; /** @stable */ navigated: boolean;
routerState: RouterState; routerState: RouterState;
url: string; url: string;
constructor(rootComponentType: Type<any>, urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, injector: Injector, loader: NgModuleFactoryLoader, compiler: Compiler, config: Routes); constructor(rootComponentType: Type<any>, urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, injector: Injector, loader: NgModuleFactoryLoader, compiler: Compiler, config: Routes);