1

I know that both of ActivatedRoute.params.forEach and ActivatedRoute.params.subscribe will return the paramaters set into route config.

Into my configuration for example:

{ path: 'auditioning/:casterType/list',  component: AuditionComponent }

When I check the parameters I do this:

this._activatedRoute.params.subscribe(
    (params) => {
       console.log(params) // return object of parameters
    }
);

Or

this._activatedRoute.params.forEach(
        (params) => {
           console.log(params) // return object of parameters
        }
    );

When I should use forEach or subscribe when getting params into path because both of them return the result what I want?

What is the best practice?

Radonirina Maminiaina
  • 6,958
  • 4
  • 33
  • 60
  • 3
    Possible duplicate of [What is the difference between Rx.Observable subscribe and forEach](http://stackoverflow.com/questions/34533197/what-is-the-difference-between-rx-observable-subscribe-and-foreach) – eko Mar 18 '17 at 08:03

1 Answers1

1

When you see the Docs it is of type Observable,

So I always use the

this._activatedRoute.params.subscribe(
    (params) => {
       console.log(params) // return object of parameters
    }
);

I hate using forEach on observables as it might cause a lot of troubles.

Aravind
  • 40,391
  • 16
  • 91
  • 110