I am a beginner in angular and I try to communicate my app with firebase, using latest versions of angular and firebase
My Code:
export class ClientService {
clientsCollection: AngularFirestoreCollection<Client>;
clientDoc: AngularFirestoreDocument<Client>;
clients: Observable<Client[]>
client: Observable<Client>
constructor(private afs: AngularFirestore) {
this.clientsCollection = this.afs.collection<Client>('clients', ref => ref.orderBy('nom'))
}
getClients(): Observable<Client[]> {
//Get id of clients
this.clients = this.clientsCollection.snapshotChanges().map(changes => {
return changes.map(action => {
const data = action.payload.doc.data() as Client;
const id = action.payload.doc.id;
return { id, data }
})
})
return this.clients;
}
}
I get this error:
12 client: Observable<Client>
~~~~~~
Error: src/app/services/client.service.ts:18:61 - error TS2339: Property 'map' does not exist on type 'Observable<DocumentChangeAction<Client>[]>'.
18 this.clients = this.clientsCollection.snapshotChanges().map(changes => {
~~~
Error: src/app/services/client.service.ts:18:65 - error TS7006: Parameter 'changes' implicitly has an 'any' type.
18 this.clients = this.clientsCollection.snapshotChanges().map(changes => {
~~~~~~~
Error: src/app/services/client.service.ts:19:26 - error TS7006: Parameter 'action' implicitly has an 'any' type.
19 return changes.map(action => {
~~~~~~
× Failed to compile.