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
*
* ```
* 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<TeamComponent> {
* 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<T> {
* ### Example
*
* ```
* class Backend {
* fetchTeam(id: string) {
* return 'someTeam';
* }
* }
*
* @Injectable()
* class TeamResolver implements Resolve<Team> {
* constructor(private backend: Backend) {}
@ -239,6 +272,7 @@ export interface CanDeactivate<T> {
* ],
* 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<T> {
* }
* ]
* })
* class AppModule {}
* ```
* @stable
*/
@ -278,6 +313,13 @@ export interface Resolve<T> {
* ### 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<T> {
* }
* ])
* ],
* 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<T> {
* }
* ]
* })
* class AppModule {}
* ```
*
* @stable

View File

@ -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;

View File

@ -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<string> = state.firstChild(state.root).params.map(p => p.id);
* const isDebug: Observable<string> = state.queryParams.map(q => q.debug);
* const id: Observable<string> = state.root.firstChild.params.map(p => p.id);
* const isDebug: Observable<string> = 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<string> = 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;

View File

@ -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,

View File

@ -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<Event>;
/** @experimental */ navigated: boolean;
/** @stable */ navigated: boolean;
routerState: RouterState;
url: string;
constructor(rootComponentType: Type<any>, urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, injector: Injector, loader: NgModuleFactoryLoader, compiler: Compiler, config: Routes);