Importing and use firebase.database in Angular 5


#1

Hey I am using firebase database.
So I imported firebase:

import * as firebase from “firebase”

when the line: const rootRef = firebase.database().ref(); is read it throws the following:

JS: ERROR Error: Uncaught (in promise): Error: com.tns.NativeScriptException: Failed to find module: “util”, relative to: app/tns_modules/

But the Utils modules exists

ON THE OTHER HAND

When I initialize the AngularFireDatabase in my constructor the app does not open:

constructor(db: AngularFireDatabase) // it does not work
even AngularFirestore

constructor(dbfs: AngularFirestore){}

dbfs.collection(‘MyColletion’) // It says Cannot read property ‘collection’ of undefined.
Could you tell me please what’s going on?

THANK YOU!


#2
  1. Did you call initi on launch?
  2. .ref(path) - methods expects a parameter.

#3
  1. Yes I have ngOnInit(){}
  2. You mean path for my firebase project account?
    const rootRef =firebase.database(“table”).ref(pathToFirebaseAccount???)

#4

If I’m not wrong the table name should go to ref method not database (assuming you are importing firebase from nativescript-plugin-firebase/app)


#5

Alright, let me try this way


#6

Sir, It’s fine now. Thanks;
it’s passes through this code: const rootRef =firebase.database().ref(“table”);

Now, why when I use: constructor(db: AngularFireDatabase) {}
it throws: ERROR Error: Uncaught (in promise): Error: com.tns.NativeScriptException: Failed to find module: “util”, relative to: app/tns_modules/ ??


#7

Sir doing: const rootRef = firebase.database().ref(“databaseName”);
It says: JS: Error in firebase.init: Error: java.lang.IllegalArgumentException: Firebase Storage URLs must point to an object in your Storage Bucket. Please obtain a URL using the Firebase Console or getDownloadUrl().

And when I use: const rootRef = firebase.database().ref(MyfirebaseBucket);
It throws the same error.
But When I use the firebaseBucket Url on the web browser it works fine.
Any idea?