I have an issue with observables in Angular 2. I can retrieve data from a DB using a service and can console.log the data in my service and resolver files, but I am unable to pass the data into my component.
I am using a service to query a database:
getExamQuestion(query) {
return this.http.get('api/question/1/1').pipe(tap(data => {
console.log("questiondata", data) // This logs the expected data
}));
}
constructor(
private examdataservice:ExamdataService){
}
resolve(route: ActivatedRouteSnapshot) {
return this.examdataservice.getExamQuestion(route.params).pipe(tap(data => {
console.log("questiondata", data) // This logs also the expected data
}));
}
My component has the following code, but I am unable to retrieve the data from the service/resolver:
ngOnInit(): void {
this.qData = this.route.snapshot.data['ExamResolver']
console.log("data", this.qData) // This logs 'undefined'
}
How can I get my component to access the resolved data? Any advice would be greatly appreciated.