title: Accessing activatedRoute.params for service
body: <p>I am working on an Angular Project that uses a lot of path parameters</p>
  
  <pre><code>/sec/:sec/subsec/:subsec/foo/:foo
  </code></pre>
  
  <p>this of course is also being use by the back end API so I need to access them, this is starting to create a bit of a tangled mess.  At present I am using <code>activatedRoute</code> in my components to gain access to these parameters. </p>
  
  <pre><code>this.activatedRoute.params.subscribe((params: Params) =&gt; {
  this.sec = params['sec'];
  </code></pre>
  
  <p>However, this is leading to me creating the exact same code over and over in every component. I would very much like to simple create a service that allows me to access these parameters, for example:</p>
  
  <pre><code>    class myParamState{
  
      sec: string;
      subsec: string
      foo: string;
      //...
  
      }
  </code></pre>
  
  <p>At this point I have managed to gain access to the router in my router outlet component, this almost does it for me.</p>
  
  <pre><code>constructor(private router: Router) {
  router.events.subscribe(val =&gt; {
  console.log(val);
  });
  }
  </code></pre>
  
  <p>Where am I stuck? I am unsure how to extract parameters from the router (not even sure if this is the best approach). If I could I would be able to just update a service I can reuse, and I would be done. </p>
  
  <p>I feel like I am missing something very obvious,maybe something built in ― I am stuck</p>