How properly subscribe to observable paramMap Angular?

Discussão em 'Angular' iniciado por A. Gladkiy, Outubro 22, 2024.

  1. A. Gladkiy

    A. Gladkiy Guest

    I can get params from paramMap:

    this.route.paramMap.subscribe((params: ParamMap) => {
    this.templateService.get(+params.get("id")!).subscribe((response: Json | JsonError) => {
    ...
    });
    });


    and also with the following way:

    this.route.paramMap
    .pipe(
    switchMap((params: ParamMap) => this.templateService.get(+params.get('id')!))
    )
    .subscribe((response: Json | JsonError) => {
    ...
    });


    But what's the difference? And what method is correct (or in other words what method match to what situations)?

    Continue reading...

Compartilhe esta Página