Hi, killing myself with this one- by 'misstake' I run "npm install firebase angularfire2 --save" and now I'm getting error
Property 'id' does not exist on type 'QueryDocumentSnapshot
'.
getEmployees(): Observable<Employee[]> {
return this.firestore.collection('companies').doc(this.company.companyId).collection('employees').snapshotChanges().map(changes => {
return changes.map(a => {
const data = a.payload.doc.data() as Employee;
data.employeeId = a.payload.doc.id;
return data;
});
});
}
what is wrong?:S
P.s tryed:
return this.firestore.collection('companies').doc(this.company.companyId).collection('employees').snapshotChanges().pipe(
map(actions => actions.map(a => {
const emp = a.payload.doc.data() as Employee;
emp.employeeId = a.payload.doc.id;
return emp;
}))
);
-no help
Hello,
I'm facing similar issue after upgrading to Angular 6, which is using new version of rxjs
I'm doing same thing, using snapshotChanges & map in 1 case to get a document with id & in other case to get collection of document with id
@surajsingh-itian sorry , should have put a solution to that before closing: U have to change your syntax to something like this:
.collection('companies').snapshotChanges().pipe(map(changes => {
return changes.map(a => {
const company = a.payload.doc.data() as Company;
company.companyId = a.payload.doc.id;
return company;
});
so the key is to use ".pipe(map("
hope it helps (y)
fetchAvailableExercises() {
this.fbSubs.push(this.db
.collection('availableExercises')
.snapshotChanges().pipe( map(docArray => {
return docArray.map(doc => {
return {
id: doc.payload.doc.id,
name: doc.payload.doc.data().name,
duration: doc.payload.doc.data().duration,
calories: doc.payload.doc.data().calories
};
});
}) )
.subscribe((exercises: ExerciseModel[]) => {
this.availableExercises = exercises;
this.exercisesChanged.next([...this.availableExercises]);
}));
}
@neo-xy @surajsingh-itian I already used pipe but its giving me the same error , plz assist me !
@CajetanRodrigues I'm not sure where this was solved but you can declare the doc to be of type any
etchAvailableExercises() {
this.fbSubs.push(this.db
.collection('availableExercises')
.snapshotChanges().pipe( map(docArray => {
return docArray.map((doc:any) => {
return {
id: doc.payload.doc.id,
name: doc.payload.doc.data().name,
duration: doc.payload.doc.data().duration,
calories: doc.payload.doc.data().calories
};
});
}) )
.subscribe((exercises: ExerciseModel[]) => {
this.availableExercises = exercises;
this.exercisesChanged.next([...this.availableExercises]);
}));
}
Most helpful comment
@CajetanRodrigues I'm not sure where this was solved but you can declare the doc to be of type any
etchAvailableExercises() {
this.fbSubs.push(this.db
.collection('availableExercises')
.snapshotChanges().pipe( map(docArray => {
return docArray.map((doc:any) => {
return {
id: doc.payload.doc.id,
name: doc.payload.doc.data().name,
duration: doc.payload.doc.data().duration,
calories: doc.payload.doc.data().calories
};
});
}) )
.subscribe((exercises: ExerciseModel[]) => {
this.availableExercises = exercises;
this.exercisesChanged.next([...this.availableExercises]);
}));
}