Question about Ionic 4 + firebase

Hi,

I have trouble to deposit data to database in firebase in Ionic 4, I tried to
create a module storage with a provider StoreToFirebaseService to save data to firebase.

I did the following:

npm install firebase angularfire2

  1. add config to app/environments/environment.ts

export const environment = {
production: false,
firebase: {
apiKey: ‘’,
authDomain: ‘’,
databaseURL: ‘’,
projectId: ‘’,
storageBucket: ‘’,
messagingSenderId: ‘’,
appId: “”
}
};

  1. storage.module.ts

import { AngularFireModule } from ‘angularfire2’;
import { environment } from ‘…/…/environments/environment’;
import { AngularFirestoreModule } from ‘angularfire2/firestore’;

@NgModule({
declarations: ,
imports: [
CommonModule,
AngularFireModule.initializeApp(environment.firebaseConfig),
AngularFirestoreModule
],
providers: [ StoreToFirebaseService ]
})
export class StorageModule { }

  1. store-to-firebase.service.ts


import { AngularFirestore } from ‘angularfire2/firestore’;

export class StoreToFirebaseService {

constructor(
public afs: AngularFirestore
) {
}

addSurvey(){
  console.log("Inside addSurvey!");
  return new Promise<any>((resolve, reject) => {
    this.afs.collection('/result').add({
      ID: "Q2",
      Result1: false,
      Result2: false
    })
    .then(
      (res) => {
        resolve(res)
      },
      err => reject(err)
    )
  })
}    

}

  1. In the component, I imported the service

import { StoreToFirebaseService } from ‘…/…/storage/store-to-firebase.service’;

export class InitiatedDrinkComponent implements OnInit {

constructor(
private storeToFirebaseService: StoreToFirebaseService
) { }

storeData(){
console.log(“Inside storeData”);
this.storeToFirebaseService.addSurvey();
}

}

  1. Fore firebase database, I start in test mode with an empty database.

But “result” is not created with the fields ID, Result1 and Result2, any suggestion? Thanks!

It is working, I had a mistake in action which never fired to store the data in my actual code.