Akses Database Firestore dari Angular

Tips Feb 12, 2020

Dear Pembaca setia,

Berikut penulis sajikan sintaks perintah yang digunakan penulis dalam mengakses Firestore lewat pemrograman di Angular. Di sini penulis membatasi pada perbedaan akses realtime dan one-time akses di Firestore:

Realtime command syntax

getRealTimeFirebaseData(groupid: string) {
	const custdetail = this.firestore
		.collection('sto-activity').doc(groupid)
		.collection('customer').snapshotChanges();

    custdetail.subscribe(result => {
		console.log('RealTime: ' + result[0].payload.doc.get('address'));
    });
}

One-time command syntax

getOneTimeFirebaseData(groupid: string, customerid: string) {
	const custdetail = this.firestore
		.collection('sto-activity').doc(groupid)
		.collection('customer').doc(customerid);
	
	custdetail.get().subscribe(result => {
		console.log('OneTime: ' + result.get('address'));
    });
}

Sekian untuk kali ini. Semoga dapat membantu.

Salam,
Penulis

Tags

Eldest Pasirula

Software Engineer, Blog Writer, $TSLA follower

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.