Advertisement
fabiobiondi

Firebase sub collections (doesn't work)

Mar 30th, 2018
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. getCourses() {
  2. return this.afs.collection<Course>('courses').snapshotChanges()
  3. .map(course => {
  4. return course.map(a => {
  5. const courseData = a.payload.doc.data()
  6. const courseId = a.payload.doc.id;
  7.  
  8. // get sections
  9. const sectionsRef = this.afs.collection(`courses/${courseId}/sections`)
  10.  
  11. sectionsRef.snapshotChanges()
  12. .subscribe(section => {
  13. return section.map(se => {
  14. const sectionData = se.payload.doc.data()
  15. const sectionId = se.payload.doc.id;
  16. const theSection = { sectionId, sectionData };
  17. console.log('theSection', theSection)
  18.  
  19. // get _items
  20. const itemsRef = this.afs.collection(`courses/${courseId}/sections/${sectionId}/items`)
  21.  
  22. itemsRef.snapshotChanges()
  23. .subscribe(item => {
  24. return item.map(i => {
  25. const itemData = i.payload.doc.data()
  26. const itemId = i.payload.doc.id;
  27. const theItem = { itemId, itemData };
  28.  
  29. console.log('theItem', theItem)
  30. return theItem
  31. });
  32. })
  33.  
  34. })
  35.  
  36. })
  37. });
  38. })
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement