Skip to content

Error using "firebase" in AngularFire2 application #585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JimLynchCodes opened this issue Oct 2, 2016 · 4 comments
Closed

Error using "firebase" in AngularFire2 application #585

JimLynchCodes opened this issue Oct 2, 2016 · 4 comments

Comments

@JimLynchCodes
Copy link

I'm trying to use firebase storage in a an Angular 2 application. I was expecting to just be able to use the AngularFire object like this af.storage, but it seems that api was never implemented in AngularFire2.

I was watching this video (https://www.youtube.com/watch?v=nMR_JPfL4qg) by @davideast where he provides a hackish way of getting to firebase storage at 6:45.

how_to_upload_to_firebase_storage_using_angular_2_-_askfirebase-_youtube

However, when IU try to add this code to my project I get this error:
error_handler.js:45EXCEPTION: Error in ./AppComponent class AppComponent - inline template:4:0 caused by: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp().ErrorHandler.handleError @ error_handler.js:45(anonymous function) @ application_ref.js:209ZoneDelegate.invoke @ zone.js:203onInvoke @ ng_zone_impl.js:43ZoneDelegate.invoke @ zone.js:202Zone.run @ zone.js:96(anonymous function) @ zone.js:462ZoneDelegate.invokeTask @ zone.js:236onInvokeTask @ ng_zone_impl.js:34ZoneDelegate.invokeTask @ zone.js:235Zone.runTask @ zone.js:136drainMicroTaskQueue @ zone.js:368
error_handler.js:47ORIGINAL EXCEPTION: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp().

project

Here is my component:

import {Component} from '@angular/core';
import {AngularFire, FirebaseObjectObservable} from 'angularfire2';
import * as firebase from 'firebase';

@Component({
  selector: 'app-firebase-list',
  templateUrl:'./firebase-list.component.html'
})
export class FirebaseListComponent {
  item: FirebaseObjectObservable<any>;

  image:string;

  constructor(af: AngularFire) {

    const storageRef = firebase.storage().ref().child('/videos/Snapchat-8007737197212799828.mp4');
    storageRef.getDownloadURL().then(url => this.image = url);


    this.item = af.database.object('/rooms/room2');
    this.item.subscribe(snapshot => console.log(snapshot.topic));


  }

  }

Also, here is my app.module.ts. Do I maybe need to change something here?

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import {FirebaseListComponent} from './firebase-list/firebase-list.component';
import { AngularFireModule } from 'angularfire2';

// Must export the config
export const firebaseConfig = {
  apiKey: 'xxxxxxxxxxxxxxxxxxxxx',
  authDomain: 'xxxxxxxxxxxxxxxxxxxxx',
  databaseURL: 'xxxxxxxxxxxxxxxxxxxxx',
  storageBucket: 'xxxxxxxxxxxxxxxxxxxxx'
};

    firebase.initializeApp(firebaseConfig)

@NgModule({
  declarations: [
    AppComponent,
    FirebaseListComponent
  ],
  imports: [
    BrowserModule,
    AngularFireModule.initializeApp(firebaseConfig),
    FormsModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Thanks!

@JimLynchCodes
Copy link
Author

Derp. I fixed it by adding firebase.initializeApp(firebaseConfig) to my app.module.ts as explained in this thread: #556

@katowulf
Copy link
Contributor

Glad you sorted this. Please use the issue template in the future when submitting questions. There's a lot of great detail here (thanks for that!) but a few key elements missing that would have helped us troubleshoot.

@sunlyear
Copy link

I think using firebase.initializeApp(firebaseConfig) is not a good solution because we are initializing another instance of firebase object. Say, we authorize user using Auth in AngularFire, the firebase (global instance) will not have all authorized information when you try to access storage ref. I made a comment in #213 base on solution from here.

@maxmumford
Copy link
Contributor

@JimTheMan safari on iOS was throwing an exception as a result of initializing a second firebase instance. The solution @sunlyear found worked perfectly for me (thanks!!!). See my comment here for more details:

#556 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants