Route params

We can pass values when navigating from one component to the other. In our example, we are passing the id value from BooksListComponent to BookDetailsComponent. We can access route parameters using the ActivatedRoute object Params property:

The code for src/app/books/book-details/book-details.component.ts is as follows:

import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Params, Router }                             from '@angular/router'; import { Location } from '@angular/common'; import 'rxjs/add/operator/switchMap'; import { BookStoreService } from '../book-store.service'; import { Book } from '../book'; @Component({   selector: 'book-details',   templateUrl: './book-details.component.html',  styleUrls: ['./book-details.component.scss'] ...

Get Building Modern Web Applications using Angular now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.