Query single Firebase object by key from a service
<p>I'm using Angular CLI + Firebase + AngularFire2 have been trying to figure out how to query a single object from Firebase using the key.</p>

<p>The basic flow would be to show a list of items, then clicking on an item would bring up the detail view for that particular item. </p>

<p>This should be a pretty common use case but the AngularFire 2 docs don't seem to give any clear examples on how I could do this.</p>

<p>I'm trying to use a service to query the items but I can't quite get it to work.</p>

<p><strong>Component</strong></p>

<pre class="lang-js prettyprint-override"><code>// COMPONENT

import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { AngularFire, FirebaseObjectObservable} from 'angularfire2';
import { Subscription } from 'rxjs';
import { ItemsService } from '../items.service';

@Component({
  selector: 'app-item-detail',
  templateUrl: './item-detail.component.html',
  styleUrls: ['./item-detail.component.css']
})
export class ItemDetailComponent implements OnInit, OnDestroy {

  private subscription: Subscription;
  private item;

  constructor(private af: AngularFire,
              private route: ActivatedRoute,
              private router: Router,
              private itemsService: ItemsService) { }


  ngOnInit() {
    this.subscription = this.route.params.subscribe(
      (param: any) =&gt; {
        let id = param['id'];
        console.log('Key: '+ id);
        this.item = this.itemsService.getItem(id);
      }
    );
  }

  ngOnDestroy() {
    this.subscription.unsubscribe();
  }

}
</code></pre>

<p><strong>Service</strong></p>

<pre class="lang-js prettyprint-override"><code>import { Injectable } from '@angular/core';
import { Headers, Http, Response } from "@angular/http";
import { AngularFire, FirebaseObjectObservable, FirebaseListObservable, FirebaseApp } from 'angularfire2';
import 'rxjs/Rx';

@Injectable()
export class ItemsService {

  private items: FirebaseListObservable&lt;any[]&gt;;
  private item: FirebaseObjectObservable&lt;any&gt;;

  constructor(private af: AngularFire) {}

  getItems(num) {
    this.items = this.af.database
      .list('/items', { query: { limitToLast: num | 20} } )
      .map( (arr) =&gt; { return arr.reverse() } ) as FirebaseListObservable&lt;any[]&gt;;
    return this.items;
  }

  getItem(id: string) {
    this.item = this.af.database.object('/items/'+id);
    this.item.subscribe(item =&gt; {
        console.log(item);
        return item;
      });
  }

}
</code></pre>