2016-11-02 3 views
1

테이블에 데이터를 설정하려고합니다. 나는이 같은 데이터를 검색해야하는 서비스가 있습니다AngularFire에서 데이터를 가져 오는 중 오류가 발생했습니다.

constructor(public af: AngularFire, userData: UserData) { 
    this.smartTableData = af.database.list('events/' + userData.user.uid +'/contacts'); 
    } 

    getData(): any { 
    return this.smartTableData; 
    } 

을 내 구성 요소는 다음과 같습니다 콘솔에서

constructor(protected service: SmartTablesService) { 
    this.service.getData().then((data) => { 
     this.source.load(data); 
    }); 
    } 

내 오류 :

zone.js:357 Error: Uncaught (in promise): Error: Error in ./SmartTables class SmartTables_Host - inline template:0:0 caused by: this.service.getData(...).then is not a function(…)

답변

2

AngularFire2이 Observables은 함께 작동하는 당신을 subscribe to. Observables가 아닌 Promises에서 사용할 수있는 정의되지 않은 함수 then을 호출하려고하기 때문에 오류가 발생합니다.

thensubscribe으로 바꾸고 데이터를 검색하려고합니다.

constructor(protected service: SmartTablesService) { 
    this.service.getData().subscribe((data) => { 
    this.source.load(data); 
    }); 
} 
관련 문제