angular/packages/examples/router/activated-route/module.ts
Joey Perrott c4b880a025 refactor: migrate docs, examples, private, service worker and upgrade to prettier formatting (#54163)
Migrate formatting to prettier for docs, examples, private, service worker and upgrade from clang-format

PR Close #54163
2024-01-30 20:08:40 +00:00

41 lines
1.3 KiB
TypeScript

/**
* @license
* Copyright Google LLC 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
*/
// #docregion activated-route
import {Component, NgModule} from '@angular/core';
// #enddocregion activated-route
import {BrowserModule} from '@angular/platform-browser';
// #docregion activated-route
import {ActivatedRoute, RouterModule} from '@angular/router';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';
// #enddocregion activated-route
// #docregion activated-route
@Component({
// #enddocregion activated-route
selector: 'example-app',
template: '...',
// #docregion activated-route
})
export class ActivatedRouteComponent {
constructor(route: ActivatedRoute) {
const id: Observable<string> = route.params.pipe(map((p) => p['id']));
const url: Observable<string> = 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 {}