title: Getting url id with params and ActivatedRoute Angular 2
body: <p>I am trying to get a uuid from the URL (which looks like <a href="https://something.com/card?id=" rel="nofollow noreferrer">https://something.com/card?id=</a><strong>where uuid goes</strong>) and then use that uuid to get a http get request. </p>
  
  <p>Right now I have my app.component.ts looks like:</p>
  
  <pre><code>private cardUuid: string;
  
  constructor(private service: AppService,
              private route: ActivatedRoute){
              let sub = this.route.params.subscribe((params: Params) =&gt; {
                    this.cardUuid = params['id'];
                    console.log(this.cardUuid)
                  })
  
  }
  
  
  ngOnInit(){
    this.service.browserUuid = 'http://address/cards?uuid=' + this.sub.cardUuid;
      console.log(this.sub.cardUuid)
  </code></pre>
  
  <p>}</p>
  
  <p>My console logs are coming back as undefined. I am wondering why that is the case? Is the method for getting the uuid wrong or is the call timing wrong?</p>
  
  <p>Any help/tips/suggestions would be much appreciated.</p>
  
  <p><strong>Update:</strong>
  after a suggestion from @Alexander Staroselsky, I restructured my method of calling the uuid from the url per angular.io docs.</p>
  
  <p>app.component.ts:</p>
  
  <pre><code>card: Card = {};
  
  ngOnInit() {
   this.route.paramMap
    .switchMap((params: ParamMap) =&gt;
      this.service.fetchCardUuid(+params.get('id')))
    .subscribe(
      card =&gt; {
        this.card = card;
        this.getVenueUuid(this.card);
      });
  }
  </code></pre>
  
  <p>app-service.ts:</p>
  
  <pre><code>public UuidUrl = 'http://websiteaddress/cards?uuid='
  
  constructor(private http: Http){}
  
  
  private extractData(res:Response) {
    let body = res.json();
    return body || [];
  }
  
  fetchCardUuid(id: number) {
    return this.http.get(this.UuidUrl + id)
      .map(this.extractData)
  }
  </code></pre>
  
  <p>However I am still not getting the app to load properly using the Uuid that is being fetched from the Url. In the console network is showing a get request of card?uuid=0.  Again, any help would be much appreciated.</p>