title: Angular 2 get routeParams in a service
body: <p>I want to shift the logic from component to service. But I found out that I can't get the routeParams in a service.</p>
  
  <p>My component looks like</p>
  
  <pre><code>import { Component, OnInit }      from '@angular/core';
  import { ActivatedRoute, Params } from '@angular/router';
  
  import { MyService }              from '../services/my.service';
  
  @Component({
    moduleId: module.id,
    templateUrl: 'my.component.html',
    styleUrls: ['my.component.css']
  })
  export class MyComponent implements OnInit {
    constructor(private myService: MyService, private route: ActivatedRoute) {;}
  
    public ngOnInit() {
      this.route.params
        .subscribe((params: Params) =&gt; {
          debugger;
          console.log(params);
        });
      this.myService.getParams()
        .subscribe((params: Params) =&gt; {
          debugger;
          console.log('Return1:');
          console.log(params);
        }, (params: Params) =&gt; {
          debugger;
          console.log('Return2:');
          console.log(params);
        }, () =&gt; {
          debugger;
          console.log('Return3:');
      });
    }
  };
  </code></pre>
  
  <p>My service looks like</p>
  
  <pre><code>import { Injectable }                     from '@angular/core';
  import { Params, ActivatedRoute }         from '@angular/router';
  
  import { Observable }                     from 'rxjs';
  
  @Injectable()
  export class MyService {
    constructor(private route: ActivatedRoute) {;}
  
    public getParams(): Observable&lt;Params&gt; {       
      this.route.params.subscribe((params: Params) =&gt; {
        debugger;
        console.log('Service1:');
        console.log(params);
      }, (params: Params) =&gt; {
        debugger;
        console.log('Service2:');
        console.log(params);
      }, () =&gt; {
        debugger;
        console.log('Service3:');
      });
      return this.route.params;
    }
  };
  </code></pre>
  
  <p>When I debug I can see that params are filled in component and empty in service. That's the result</p>
  
  <pre><code>Component:
  Object {param: "1"}
  Service1:
  Object {}
  Return1:
  Object {}
  </code></pre>
  
  <p>I'm using Angular 2.0.0. Why the difference in component and service? Is it possible to get params in a service?</p>
  
  <p>EDIT: 
  <a href="https://github.com/angular/angular/issues/11023" rel="noreferrer">https://github.com/angular/angular/issues/11023</a></p>