2016-09-14 32 views
2

我正在嘗試編寫一個查詢,該查詢將從基於密鑰的集合中提取單個項目。

我一直在尋找和下面的教程很多,但一切似乎只是展示如何獲取列表如下圖所示:

我想在$鍵和查詢傳遞和拉一條記錄。任何建議或方向的來源,可以幫助將不勝感激。

import { Injectable } from '@angular/core'; 

import { Customer } from "./customer"; 

import { AngularFire, FirebaseListObservable} from 'angularfire2'; 

@Injectable() 
export class CustomerService { 

    customer: Customer; 
    customers: FirebaseListObservable<Customer[]>; 
    categories: FirebaseListObservable<Category[]>; 

    constructor(private af: AngularFire) { } 

    getCustomer(customerIndex: number) { 

     this.customers = this.af.database.list('customer'); 

     return this.customers; 
    } 
} 

回答

3

如果你知道你可以做到這一點的關鍵在於:

this.af.database.object('/customers/' + key) 
    .subscribe(customer =>{ 
    // Assuming that name is a value of customer you can say 
    var name = customer.name; 
    ... 
    } 

當然,這是假設的「客戶」是您以前推客戶名單。

+0

謝謝 - 我新的它會很簡單,真的很感謝你的幫助 – ccocker