This repository was archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
This repository was archived by the owner on Sep 4, 2020. It is now read-only.
Multiple database of same firebase project #94
Copy link
Copy link
Open
Description
Hi how are you? I need your help because I have implemented your library for an ionic app and I need the following:
- I need to know how to do to point to a particular namespace created with angularfire2. Basically I need to be able to create a new instance of AngularFireOfflineDatabase from an ionic component.
Ex:
new AngularFireOfflineDatabase (AngularFireDatabase, token, LocalUpdateService);
In this case I would like to be able to pass a particular instance of AngularFireDatabase. The token and LocalUpdateService do not know how to pass it.
Basically my application needs to connect to different firebase database of the same project. With angularfire2 I was able to do this but with AngularFireOffline it always points to the global connection of angularfire2.
My service look that and I have problem with LOCAL_UPDATE_SERVICE_PROVIDER :
import { Injectable } from "@angular/core";
import { Events } from 'ionic-angular';
import { AngularFireOfflineDatabase } from 'angularfire2-offline';
import { LOCALFORAGE_PROVIDER, LocalForageToken } from 'angularfire2-offline/database/offline-storage/localforage';
import { LocalUpdateService, LOCAL_UPDATE_SERVICE_PROVIDER } from 'angularfire2-offline/database/offline-storage/local-update-service';
/** 3rd-party imports */
import { AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from "angularfire2/database";
import { _firebaseAppFactory } from "angularfire2/firebase.app.module";
import { FirebaseAppConfig } from "angularfire2";
import firebase from 'firebase/app';
@Injectable()
export class FirebaseService {
private _db: AngularFireDatabase;
constructor(public events: Events) {
events.subscribe('workspace:selected', (config, firebaseAppName) => {
console.log("Event workspace:selected called");
this.initFirebaseApp(config, firebaseAppName);
});
}
/** Function to initialize firebase application and
* get DB provider for the corresponding application.
*/
public initFirebaseApp(config: FirebaseAppConfig, firebaseAppName: string) {
//firebase.app().delete().then(() => {
//const secondAppConfig = firebase.initializeApp(config);
this._db = new AngularFireDatabase(_firebaseAppFactory(config, firebaseAppName));
let dboffline = new AngularFireOfflineDatabase(this._db, LOCALFORAGE_PROVIDER, LOCAL_UPDATE_SERVICE_PROVIDER);
dboffline.list("projects").subscribe((projects) => {
console.log("afoDatabase called");
console.log(projects);
})
//});
}
/** Function to get firebase DB list */
public getList(path: string): FirebaseListObservable<{}> {
return this._db.list(path);
}
/** Function to get firebase DB object */
public getObject(path: string): FirebaseObjectObservable<{}> {
return this._db.object(path);
}
public db() {
return this._db;
}
}```
Thank you.
Metadata
Metadata
Assignees
Labels
No labels