I have two fire store collection with following reference image . I want to get the firstName and title. Here signup_id is referenced from coll-signup document id. Following code given below what i did.
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 print 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;
}
}
this is possible to do fire store? I'm newbie in fire store.Please help me. Thanks!
You need to combine two collections.
try this code
For anyone experiencing issues, combining documents in Firebase Cloud Firestore while using Angular6, RxJS 6 and AngularFire v5.0 try the following code
Model feed.ts
Service feed.service.ts
To print all the data