O'Reilly logo

Learning Angular for .NET Developers by Rajesh Gunasundaram

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Introducing ParamMap in router

Angular has introduced a new interface, ParamMap, to map the parameters in a URL. We can use paramMap or queryParamMap to access parameters of a URL. ParamMap has methods such as get() to get a value or getAll() to get all the values of the query parameters, as follows:

const id =   this.route.snapshot.paramMap.get('bookId');   
this.bookService.get(id).subscribe(b   => this.book = b);   

In an observable, we need to use ParamMap as illustrated:

this.route.paramMap   
  .map((params: ParamMap) =>   params.get('bookId'))   
  .switchMap(id =>   this.bookService.get(id))   
  .subscribe(b => this.book =   b);   

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required