win4win
win4win

Reputation: 363

Angular Firestore get a single value from Doc

In my .ts file I am trying to get a single value named 'index' from AngularFirestoreDocument.

interface item {
  index:string;
}

export class appComponent{

constructor(
public router:Router,
public afs: AngularFirestore, 
public afAuth: AngularFireAuth

)

itemCollection: AngularFirestoreCollection<item>;
items: any;

itemDoc: AngularFirestoreDocument<item>;
Item: Observable<item>;

  ngOnInit() {

   itemDoc = this.afs.doc(this.accounts+this.email).collection('Items');

 }
}

just trying to retrieve the index value from itemDoc since I'm directly inside the Doc.

Upvotes: 2

Views: 742

Answers (1)

Reza
Reza

Reputation: 19843

it should be

async ngOnInit() {
  const docRef = await this.afs.collection('yourcollectionname').doc('yourdocId');
  const data = (await docRef.get()).data();
}

Upvotes: 3

Related Questions