2016-05-26 2 views
0

Я хочу разработать приложение образца с ионным 2 и angularfire 2.angularfire 2 TypeError: Firebase не конструктор

Я успешно интегрирован angularfire 2 в ионическом 2, но когда я попытался принести мои данные firebase я получил эту ошибку в консоли браузера:

`XCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in :0:0 
ORIGINAL EXCEPTION: TypeError: Firebase is not a constructor 
ORIGINAL STACKTRACE: 
TypeError: Firebase is not a constructor 
    at exports.COMMON_PROVIDERS.core_1.provide.useFactory (http://localhost:8100/build/js/app.bundle.js:38023:45) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:28:81) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:34:98) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:40:97) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:52:124) 
    at DebugAppView._View_MyApp_Host0.injectorGetInternal (MyApp_Host.template.js:74:80) 
    at DebugAppView.AppView.injectorGet (http://localhost:8100/build/js/app.bundle.js:25671:21) 
    at DebugAppView.injectorGet (http://localhost:8100/build/js/app.bundle.js:25844:49) 
    at ElementInjector.get (http://localhost:8100/build/js/app.bundle.js:25299:33) 
    at ElementInjector.get (http://localhost:8100/build/js/app.bundle.js:25302:48) 
ERROR CONTEXT: 
[object Object] 
app.bundle.js:33661 EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in :0:0 
ORIGINAL EXCEPTION: TypeError: Firebase is not a constructor 
ORIGINAL STACKTRACE: 
TypeError: Firebase is not a constructor 
    at exports.COMMON_PROVIDERS.core_1.provide.useFactory (http://localhost:8100/build/js/app.bundle.js:38023:45) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:28:81) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:34:98) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:40:97) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:52:124) 
    at DebugAppView._View_MyApp_Host0.injectorGetInternal (MyApp_Host.template.js:74:80) 
    at DebugAppView.AppView.injectorGet (http://localhost:8100/build/js/app.bundle.js:25671:21) 
    at DebugAppView.injectorGet (http://localhost:8100/build/js/app.bundle.js:25844:49) 
    at ElementInjector.get (http://localhost:8100/build/js/app.bundle.js:25299:33) 
    at ElementInjector.get (http://localhost:8100/build/js/app.bundle.js:25302:48) 
ERROR CONTEXT: 
[object Object]BrowserDomAdapter.logError @ app.bundle.js:33661 
app.bundle.js:33661 STACKTRACE:BrowserDomAdapter.logError @ app.bundle.js:33661 
app.bundle.js:33661 Error: Uncaught (in promise): EXCEPTION: Error in :0:0 
ORIGINAL EXCEPTION: TypeError: Firebase is not a constructor 
ORIGINAL STACKTRACE: 
TypeError: Firebase is not a constructor 
    at exports.COMMON_PROVIDERS.core_1.provide.useFactory (http://localhost:8100/build/js/app.bundle.js:38023:45) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:28:81) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:34:98) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:40:97) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:52:124) 
    at DebugAppView._View_MyApp_Host0.injectorGetInternal (MyApp_Host.template.js:74:80) 
    at DebugAppView.AppView.injectorGet (http://localhost:8100/build/js/app.bundle.js:25671:21) 
    at DebugAppView.injectorGet (http://localhost:8100/build/js/app.bundle.js:25844:49) 
    at ElementInjector.get (http://localhost:8100/build/js/app.bundle.js:25299:33) 
    at ElementInjector.get (http://localhost:8100/build/js/app.bundle.js:25302:48) 
ERROR CONTEXT: 
[object Object] 
    at resolvePromise (http://localhost:8100/build/js/zone.js:538:32) 
    at resolvePromise (http://localhost:8100/build/js/zone.js:523:18) 
    at http://localhost:8100/build/js/zone.js:571:18 
    at ZoneDelegate.invokeTask (http://localhost:8100/build/js/zone.js:356:38) 
    at Object.NgZoneImpl.inner.inner.fork.onInvokeTask (http://localhost:8100/build/js/app.bundle.js:30460:41) 
    at ZoneDelegate.invokeTask (http://localhost:8100/build/js/zone.js:355:43) 
    at Zone.runTask (http://localhost:8100/build/js/zone.js:256:48) 
    at drainMicroTaskQueue (http://localhost:8100/build/js/zone.js:474:36) 
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:8100/build/js/zone.js:426:22)BrowserDomAdapter.logError @ app.bundle.js:33661 
zone.js:461 Unhandled Promise rejection: EXCEPTION: Error in :0:0 
ORIGINAL EXCEPTION: TypeError: Firebase is not a constructor 
ORIGINAL STACKTRACE: 
TypeError: Firebase is not a constructor 
    at exports.COMMON_PROVIDERS.core_1.provide.useFactory (http://localhost:8100/build/js/app.bundle.js:38023:45) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:28:81) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:34:98) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:40:97) 
    at DebugAppView.Object.defineProperty.get (MyApp_Host.template.js:52:124) 
    at DebugAppView._View_MyApp_Host0.injectorGetInternal (MyApp_Host.template.js:74:80) 
    at DebugAppView.AppView.injectorGet (http://localhost:8100/build/js/app.bundle.js:25671:21) 
    at DebugAppView.injectorGet (http://localhost:8100/build/js/app.bundle.js:25844:49) 
    at ElementInjector.get (http://localhost:8100/build/js/app.bundle.js:25299:33) 
    at ElementInjector.get (http://localhost:8100/build/js/app.bundle.js:25302:48) 
ERROR CONTEXT: 
[object Object] ; Zone: angular ; Task: Promise.then ; Value: ViewWrappedExceptionconsoleError @ zone.js:461 
zone.js:463 Error: Uncaught (in promise): EXCEPTION: Error in :0:0(…)consoleError @ zone.js:463 
app.bundle.js:74808 Native: tried calling StatusBar.styleDefault, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator` 

Вот мой app.ts

import {App, Platform} from 'ionic-angular'; 
 
import {StatusBar} from 'ionic-native'; 
 
import {HomePage} from './pages/home/home'; 
 
import { FIREBASE_PROVIDERS, defaultFirebase} from 'angularfire2'; 
 

 

 
@App({ 
 
    template: '<ion-nav [root]="rootPage"></ion-nav>', 
 
    providers: [ 
 
    FIREBASE_PROVIDERS, 
 
    defaultFirebase('https://samplequizapp-50eb5.firebaseio.com') 
 
    ], 
 
    config: {} // http://ionicframework.com/docs/v2/api/config/Config/ 
 
}) 
 
export class MyApp { 
 
    rootPage: any = HomePage; 
 

 
    constructor(platform: Platform) { 
 
    platform.ready().then(() => { 
 
     // Okay, so the platform is ready and our plugins are available. 
 
     // Here you can do any higher level native things you might need. 
 
     StatusBar.styleDefault(); 
 
    }); 
 
    } 
 
}

и это мой home.ts

import {Page} from 'ionic-angular'; 
 
import { AngularFire, FirebaseListObservable } from 'angularfire2'; 
 

 
@Page({ 
 
    templateUrl: 'build/pages/home/home.html' 
 
}) 
 
export class HomePage { 
 
    myData: FirebaseListObservable<any[]>; 
 

 
    constructor(public af: AngularFire) { 
 
    this.myData = af.database.list('/userId') 
 
    console.log(this.myData) 
 
    } 
 

 
};

спасибо :)

ответ

1

Я подозреваю, что вы установили неправильную версию firebase. Вам необходимо продолжить использование версии 2.4.2 firebase, поскольку AngularFire2 не обновлен для поддержки последней версии firebase.

Более подробная информация здесь: https://github.com/aaronksaunders/ionic2-angularfire-sample

ЗАКАНЧИВАТЬ package.json

+0

Я установил Firebase 3, но потом я изменил его на 2.4.2, но ошибка так же, как это было раньше. –

+0

Могу я увидеть весь проект где-нибудь? Вы проверили свой пакет.json против проекта, на который я ссылался ... –

+0

Вы были правы, проблема была в версии firebase, я создал новый проект и установил firebase v2.4.2, и теперь все запущено, спасибо –

Смежные вопросы