From 9a807bd26ac92e78f07f15a90c6fa591933c0a7e Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Sun, 7 Apr 2019 21:10:28 +0200 Subject: [PATCH] docs(router): Move ActivatedRoute example to mini-app (#29755) PR Close #29755 --- .../router/activated-route/BUILD.bazel | 35 ++++++++++++++ .../examples/router/activated-route/main.ts | 12 +++++ .../examples/router/activated-route/module.ts | 46 +++++++++++++++++++ packages/router/src/router_state.ts | 13 +----- 4 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 packages/examples/router/activated-route/BUILD.bazel create mode 100644 packages/examples/router/activated-route/main.ts create mode 100644 packages/examples/router/activated-route/module.ts diff --git a/packages/examples/router/activated-route/BUILD.bazel b/packages/examples/router/activated-route/BUILD.bazel new file mode 100644 index 0000000000..a73eafe177 --- /dev/null +++ b/packages/examples/router/activated-route/BUILD.bazel @@ -0,0 +1,35 @@ +package(default_visibility = ["//visibility:public"]) + +load("//tools:defaults.bzl", "ng_module") +load("@npm_bazel_typescript//:index.bzl", "ts_devserver") + +ng_module( + name = "router_activated_route_examples", + srcs = glob( + ["**/*.ts"], + ), + # TODO: FW-1004 Type checking is currently not complete. + type_check = False, + deps = [ + "//packages/core", + "//packages/platform-browser", + "//packages/platform-browser-dynamic", + "//packages/router", + "@npm//rxjs", + ], +) + +ts_devserver( + name = "devserver", + entry_module = "@angular/examples/router/activated-route/main", + index_html = "//packages/examples:index.html", + port = 4200, + scripts = [ + "@npm//node_modules/tslib:tslib.js", + "//tools/rxjs:rxjs_umd_modules", + ], + static_files = [ + "@npm//node_modules/zone.js:dist/zone.js", + ], + deps = [":router_activated_route_examples"], +) diff --git a/packages/examples/router/activated-route/main.ts b/packages/examples/router/activated-route/main.ts new file mode 100644 index 0000000000..5ac1a58e47 --- /dev/null +++ b/packages/examples/router/activated-route/main.ts @@ -0,0 +1,12 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; +import {AppModuleNgFactory} from './module.ngfactory'; + +platformBrowserDynamic().bootstrapModuleFactory(AppModuleNgFactory); diff --git a/packages/examples/router/activated-route/module.ts b/packages/examples/router/activated-route/module.ts new file mode 100644 index 0000000000..63c2b9a47e --- /dev/null +++ b/packages/examples/router/activated-route/module.ts @@ -0,0 +1,46 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ +// tslint:disable: no-duplicate-imports +import {NgModule} from '@angular/core'; +// #docregion activated-route +import {Component} from '@angular/core'; +// #enddocregion activated-route +import {BrowserModule} from '@angular/platform-browser'; +import {RouterModule} from '@angular/router'; + +// #docregion activated-route +import {ActivatedRoute} from '@angular/router'; +import {Observable} from 'rxjs'; +import {map} from 'rxjs/operators'; +// #enddocregion activated-route +// tslint:enable: no-duplicate-imports +// #docregion activated-route + +@Component({ + // #enddocregion activated-route + selector: 'example-app', + template: '...' + // #docregion activated-route +}) +export class ActivatedRouteComponent { + constructor(route: ActivatedRoute) { + const id: Observable = route.params.pipe(map(p => p.id)); + const url: Observable = route.url.pipe(map(segments => segments.join(''))); + // route.data includes both `data` and `resolve` + const user = route.data.pipe(map(d => d.user)); + } +} +// #enddocregion activated-route + +@NgModule({ + imports: [BrowserModule, RouterModule.forRoot([])], + declarations: [ActivatedRouteComponent], + bootstrap: [ActivatedRouteComponent] +}) +export class AppModule { +} diff --git a/packages/router/src/router_state.ts b/packages/router/src/router_state.ts index 2f1d30fb6d..10ee3e35f3 100644 --- a/packages/router/src/router_state.ts +++ b/packages/router/src/router_state.ts @@ -91,17 +91,8 @@ export function createEmptyStateSnapshot( * Contains the information about a route associated with a component loaded in an * outlet. An `ActivatedRoute` can also be used to traverse the router state tree. * - * ``` - * @Component({...}) - * class MyComponent { - * constructor(route: ActivatedRoute) { - * const id: Observable = route.params.pipe(map(p => p.id)); - * const url: Observable = route.url.pipe(map(segments => segments.join(''))); - * // route.data includes both `data` and `resolve` - * const user = route.data.pipe(map(d => d.user)); - * } - * } - * ``` + * {@example router/activated-route/module.ts region="activated-route" + * header="activated-route.component.ts" linenums="false"} * * @publicApi */