Skip to content

Troubles with Basic Example #13

@luigi37

Description

@luigi37

Expected Behavior

I expect any of the console messages from the basic example

Actual Behavior

I get error
Uncaught (in promise) TypeError: db.collection is not a function
at lp.js: xxxx
at

Steps to Reproduce the Problem

Used this code.
Plugin version is 1.3.2

function onceLoaded() {
console.log('aaa');

    var options = {
            "datePrefix": '__DATE:',
            "fieldValueDelete": "__DELETE",
            "fieldValueServerTimestamp": "__SERVERTIMESTAMP",
            "persist": true,
            "timestampsInSnapshots": true,  // <-- set true
            "config": {}
        };

    console.log("cordova.platformId: "+cordova.platformId);
    
    if (cordova.platformId === "browser") {
        options.config = {
            apiKey: "my_apy_key",
            authDomain: "localhost",
            projectId: "my_project_id"
        };
    }

    Firestore.initialise(options).then(function(db) {
    // Add a second document with a generated ID.
        db.collection("users").add({
            first: "Alan",
            middle: "Mathison",
            last: "Turing",
            born: 1912
        })
        .then(function(docRef) {
            console.log("Document written with ID: ", docRef.id);
        })
        .catch(function(error) {
            console.error("Error adding document: ", error);
        });
    });   

}
var app = {
// Application Constructor
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},

// deviceready Event Handler
//
// Bind any cordova events here. Common events are:
// 'pause', 'resume', etc.
onDeviceReady: function() {
    this.receivedEvent('deviceready');
    
    onceLoaded();
},

// Update DOM on a Received Event
receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
}

};

app.initialize();

Specifications

  • Plugin version: 3.1.2
  • Framework: Cordova
  • Framework version: 7.1.0
  • Operating system: Linux Ubuntu

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions