Ad
How To Use Two Firebase Database In Angular Application
I have a environment variable like this
export const environment = {
production: false,
firebaseConfig: {
apiKey: '',
authDomain: '',
databaseURL: '',
projectId: '',
storageBucket: '',
messagingSenderId: '',
appId: '1:1702713223' },
firebase: {
apiKey: '',
authDomain: '',
databaseURL: '',
projectId: '',
storageBucket: '',
messagingSenderId: '',
appId: '1:37840' } };
I need to use environment.firebaseconfig in one component and environment.firebase in another component.
I am using angularfire for firebase connection, i have tried importing at the module level for initialization, but by defalut only one environment variable is set.
Any solution would be appreciated
Ad
Answer
Please have a look into this solution
// ... do all required imports
import {
firebaseConfigA, firebaseAppNameA,
firebaseConfigB, firebaseAppNameB
} from "@app/env";
import { FirebaseService } from "../../services/firebase.service";
@Component({
selector : "page-home",
templateUrl : "home.html"
})
export class ScannerDemoPage implements OnInit {
constructor(private _firebaseService: FirebaseService) { }
ngOnInit() {
// Initialize 1st application
this._firebaseService.initFirebaseApp(firebaseConfigA, firebaseAppNameA);
let myList = this._firebaseService.getList("/path1");
// Initialize 2nd application
this._firebaseService.initFirebaseApp(firebaseConfigB, firebaseAppNameB);
let myObj = this._firebaseService.getObject("/path2");
}
}
Ad
source: stackoverflow.com
Related Questions
- → Make a Laravel collection into angular array (octobercms)
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → Angularjs not working inside laravel form
- → Analysis of Flux implementations
- → how to write react component to construct HTML DOM
- → angular ng-repeat and images in a row
- → Conditional BG Color on AngularJS
- → Should I 'use strict' for every single javascript function I write?
- → getting the correct record in Angular with a json feed and passed data
- → "Undefined is not a function" at .toBe fucntion
- → angularjs data binding issue
- → Angular / JavaScript auto hydrate an instance
- → Convert generic text string in json object into valid url using Angular
Ad