I have two fire store collections with the following reference images: https://i.sstatic.net/QVJkZ.pnghttps://i.sstatic.net/0QFRi.png. I am trying to retrieve the firstName and title from these collections. The signup_id is referenced from the document id of coll-signup. Below is the code snippet of what I have done so far:
Model feed.ts
export interface Feed {
firstName? : string;
signup_id? : string;
title? : string;
}
news feed.component template
<ul *ngFor="let feed of feeds">
<!-- <li>{{feed.firstName}}</li> --> // Here I want to display my first name
<li>{{feed.title}}</li>
<li>{{feed.signup_id}}</li>
</ul>
news-feed.component.ts
import { Component, OnInit } from '@angular/core';
import { Feed } from '../../models/feed';
import { FeedService } from '../../services/feed.service';
@Component({
selector: 'app-news-feed',
templateUrl: './news-feed.component.html',
styleUrls: ['./news-feed.component.css']
})
export class NewsFeedComponent implements OnInit {
feeds : Feed[];
constructor(private feedService: FeedService) { }
ngOnInit() {
this.feedService.sellectAllNews().subscribe(feeds => {
this.feeds = feeds;
})
}
}
feed.service.ts
import { AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument } from 'angularfire2/firestore';
import { Observable } from 'rxjs/Observable';
import { Feed } from '../models/feed';
@Injectable()
export class FeedService {
feedCollection : AngularFirestoreCollection<Feed>;
feedItem : Observable<Feed[]>;
constructor(private afs : AngularFirestore) {
this.collectionInitialization();
}
collectionInitialization() {
// I think here I have to modify or add next collection to will get the output
this.feedCollection = this.afs.collection('col-challange');
this.feedItem = this.feedCollection.stateChanges().map(changes => {
return changes.map(a => {
const data = a.payload.doc.data() as Feed;
return data;
})
})
}
sellectAllNews() {
this.collectionInitialization();
return this.feedItem;
}
}
Is it possible to achieve this in Firestore? I am new to Firestore. Any help would be appreciated. Thank you!