Complete the code to initialize Firebase in an Angular app.
import { initializeApp } from 'firebase/app'; const firebaseConfig = { apiKey: 'your-api-key', authDomain: 'your-auth-domain', projectId: 'your-project-id', }; const app = initializeApp([1]);
The initializeApp function requires the Firebase configuration object, which is named firebaseConfig here.
Complete the code to import Firestore service from Firebase in Angular.
import { getFirestore } from '[1]'; const db = getFirestore(app);
The Firestore service is imported from firebase/firestore to use the full Firestore features.
Fix the error in the Angular Firestore query to get a collection.
import { collection, getDocs } from 'firebase/firestore'; async function fetchUsers() { const usersCol = collection(db, [1]); const userSnapshot = await getDocs(usersCol); return userSnapshot.docs.map(doc => doc.data()); }
The collection name must be a string, so it should be enclosed in quotes like 'users'.
Fill both blanks to add a document to Firestore with Angular.
import { collection, addDoc } from 'firebase/firestore'; async function addUser() { const usersCol = collection(db, [1]); const docRef = await addDoc(usersCol, [2]); return docRef.id; }
The collection name is 'users' and the document data is an object with user details like { name: 'Alice', age: 30 }.
Fill all three blanks to update a Firestore document in Angular.
import { doc, updateDoc } from 'firebase/firestore'; async function updateUser() { const userDoc = doc(db, [1], [2]); await updateDoc(userDoc, [3]); }
To update a document, specify the collection 'users', the document ID 'user123', and the update data object { age: 31 }.