Skip to content

Commit c74a438

Browse files
vsavkinvicb
authored andcommitted
docs(router): fix up the exampesd
1 parent c350ba2 commit c74a438

File tree

5 files changed

+59
-11
lines changed

5 files changed

+59
-11
lines changed

modules/@angular/router/src/interfaces.ts

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ import {ActivatedRouteSnapshot, RouterStateSnapshot} from './router_state';
1818
* ### Example
1919
*
2020
* ```
21+
* class UserToken {}
22+
* class Permissions {
23+
* canActivate(user: UserToken, id: string): boolean {
24+
* return true;
25+
* }
26+
* }
27+
*
2128
* @Injectable()
2229
* class CanActivateTeam implements CanActivate {
2330
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
@@ -40,8 +47,9 @@ import {ActivatedRouteSnapshot, RouterStateSnapshot} from './router_state';
4047
* }
4148
* ])
4249
* ],
43-
* providers: [CanActivateTeam]
50+
* providers: [CanActivateTeam, UserToken, Permissions]
4451
* })
52+
* class AppModule {}
4553
* ```
4654
*
4755
* You can also provide a function with the same signature instead of the class:
@@ -64,6 +72,7 @@ import {ActivatedRouteSnapshot, RouterStateSnapshot} from './router_state';
6472
* }
6573
* ]
6674
* })
75+
* class AppModule {}
6776
* ```
6877
*
6978
* @stable
@@ -79,6 +88,13 @@ export interface CanActivate {
7988
* ### Example
8089
*
8190
* ```
91+
* class UserToken {}
92+
* class Permissions {
93+
* canActivate(user: UserToken, id: string): boolean {
94+
* return true;
95+
* }
96+
* }
97+
*
8298
* @Injectable()
8399
* class CanActivateTeam implements CanActivate {
84100
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
@@ -106,8 +122,9 @@ export interface CanActivate {
106122
* }
107123
* ])
108124
* ],
109-
* providers: [CanActivateTeam]
125+
* providers: [CanActivateTeam, UserToken, Permissions]
110126
* })
127+
* class AppModule {}
111128
* ```
112129
*
113130
* You can also provide a function with the same signature instead of the class:
@@ -135,6 +152,7 @@ export interface CanActivate {
135152
* }
136153
* ]
137154
* })
155+
* class AppModule {}
138156
* ```
139157
*
140158
* @stable
@@ -151,6 +169,13 @@ export interface CanActivateChild {
151169
* ### Example
152170
*
153171
* ```
172+
* class UserToken {}
173+
* class Permissions {
174+
* canDeactivate(user: UserToken, id: string): boolean {
175+
* return true;
176+
* }
177+
* }
178+
*
154179
* @Injectable()
155180
* class CanDeactivateTeam implements CanDeactivate<TeamComponent> {
156181
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
@@ -174,8 +199,9 @@ export interface CanActivateChild {
174199
* }
175200
* ])
176201
* ],
177-
* providers: [CanDeactivateTeam]
202+
* providers: [CanDeactivateTeam, UserToken, Permissions]
178203
* })
204+
* class AppModule {}
179205
* ```
180206
*
181207
* You can also provide a function with the same signature instead of the class:
@@ -198,6 +224,7 @@ export interface CanActivateChild {
198224
* }
199225
* ]
200226
* })
227+
* class AppModule {}
201228
* ```
202229
*
203230
* @stable
@@ -213,6 +240,12 @@ export interface CanDeactivate<T> {
213240
* ### Example
214241
*
215242
* ```
243+
* class Backend {
244+
* fetchTeam(id: string) {
245+
* return 'someTeam';
246+
* }
247+
* }
248+
*
216249
* @Injectable()
217250
* class TeamResolver implements Resolve<Team> {
218251
* constructor(private backend: Backend) {}
@@ -239,6 +272,7 @@ export interface CanDeactivate<T> {
239272
* ],
240273
* providers: [TeamResolver]
241274
* })
275+
* class AppModule {}
242276
* ```
243277
*
244278
* You can also provide a function with the same signature instead of the class.
@@ -263,6 +297,7 @@ export interface CanDeactivate<T> {
263297
* }
264298
* ]
265299
* })
300+
* class AppModule {}
266301
* ```
267302
* @stable
268303
*/
@@ -278,6 +313,13 @@ export interface Resolve<T> {
278313
* ### Example
279314
*
280315
* ```
316+
* class UserToken {}
317+
* class Permissions {
318+
* canLoadChildren(user: UserToken, id: string): boolean {
319+
* return true;
320+
* }
321+
* }
322+
*
281323
* @Injectable()
282324
* class CanLoadTeamSection implements CanLoad {
283325
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
@@ -300,8 +342,9 @@ export interface Resolve<T> {
300342
* }
301343
* ])
302344
* ],
303-
* providers: [CanLoadTeamSection]
345+
* providers: [CanLoadTeamSection, UserToken, Permissions]
304346
* })
347+
* class AppModule {}
305348
* ```
306349
*
307350
* You can also provide a function with the same signature instead of the class:
@@ -325,6 +368,7 @@ export interface Resolve<T> {
325368
* }
326369
* ]
327370
* })
371+
* class AppModule {}
328372
* ```
329373
*
330374
* @stable

modules/@angular/router/src/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {TreeNode} from './utils/tree';
3636
declare var Zone: any;
3737

3838
/**
39-
* @experimental
39+
* @stable
4040
*/
4141
export interface NavigationExtras {
4242
/**
@@ -235,7 +235,7 @@ export class Router {
235235
/**
236236
* Indicates if at least one navigation happened.
237237
*
238-
* @experimental
238+
* @stable
239239
*/
240240
navigated: boolean = false;
241241

modules/@angular/router/src/router_state.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ import {Tree, TreeNode} from './utils/tree';
2323
* ### Usage
2424
*
2525
* ```
26+
* @Component({template:''})
2627
* class MyComponent {
2728
* constructor(router: Router) {
2829
* const state = router.routerState;
29-
* const id: Observable<string> = state.firstChild(state.root).params.map(p => p.id);
30-
* const isDebug: Observable<string> = state.queryParams.map(q => q.debug);
30+
* const id: Observable<string> = state.root.firstChild.params.map(p => p.id);
31+
* const isDebug: Observable<string> = state.root.queryParams.map(q => q.debug);
3132
* }
3233
* }
3334
* ```
@@ -79,6 +80,7 @@ export function createEmptyStateSnapshot(
7980
* ### Usage
8081
*
8182
* ```
83+
* @Component({template:''})
8284
* class MyComponent {
8385
* constructor(route: ActivatedRoute) {
8486
* const id: Observable<string> = route.params.map(p => p.id);
@@ -153,6 +155,7 @@ export class InheritedResolve {
153155
* ### Usage
154156
*
155157
* ```
158+
* @Component({template:''})
156159
* class MyComponent {
157160
* constructor(route: ActivatedRoute) {
158161
* const id: string = route.snapshot.params.id;
@@ -218,6 +221,7 @@ export class ActivatedRouteSnapshot {
218221
* ### Usage
219222
*
220223
* ```
224+
* @Component({template:''})
221225
* class MyComponent {
222226
* constructor(router: Router) {
223227
* const snapshot = router.routerState.snapshot;

modules/@angular/router/testing/router_testing_module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class SpyNgModuleFactoryLoader implements NgModuleFactoryLoader {
3737
/**
3838
* Router setup factory function used for testing.
3939
*
40-
* @experimental
40+
* @stable
4141
*/
4242
export function setupTestingRouter(
4343
urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location,

tools/public_api_guard/router/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export declare class NavigationError {
110110
toString(): string;
111111
}
112112

113-
/** @experimental */
113+
/** @stable */
114114
export interface NavigationExtras {
115115
fragment?: string;
116116
preserveFragment?: boolean;
@@ -172,7 +172,7 @@ export declare class Router {
172172
config: Routes;
173173
errorHandler: ErrorHandler;
174174
events: Observable<Event>;
175-
/** @experimental */ navigated: boolean;
175+
/** @stable */ navigated: boolean;
176176
routerState: RouterState;
177177
url: string;
178178
constructor(rootComponentType: Type<any>, urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, injector: Injector, loader: NgModuleFactoryLoader, compiler: Compiler, config: Routes);

0 commit comments

Comments
 (0)