2016-09-14 3 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