title: angular service for querying URL query parametrs
body: <p>I'm trying to create a service in angular 5, which will query the URL parameters, extract required parameters and assign it to  specific type of interface which I created. I tried this, but it is not working:</p>
  
  <pre><code>export class UrlQueryService {
  
    urlParams = {} as UrlQueryParams;
  
    constructor( private router: Router, private route: ActivatedRoute) {
  
    }
  
    getParams() {
      this.route.queryParams.
      subscribe(
        (params: Params) =&gt; {
          this.urlParams.id = params['id'];
          this.urlParams.name = params['name']
  
        }
  
      )
  
      return this.urlParams;
    }
  
  }
  </code></pre>
  
  <p>I wanted my service return parameters, but when I cal this service in my component I'm getting 'id' and 'name' undefined</p>