我正在使用Ionic2,当我转到localhost:8100(执行 ionic serve
后)后,我收到了您在下图中看到的错误 .
app.component.ts 看起来像这样:
import firebase from 'firebase';
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from 'ionic-native';
import { HomePage } from '../pages/home/home';
@Component({
template: `<ion-nav [root]="rootPage"></ion-nav>`
})
export class MyApp {
rootPage = HomePage;
constructor(platform: Platform) {
platform.ready().then(() => {
var config = {
apiKey: ".....",
authDomain: "......",
databaseURL: ".....",
storageBucket: ".....",
messagingSenderId: "......"
};
firebase.initializeApp(config);
StatusBar.styleDefault();
});
}
}
app.module.ts
import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: []
})
export class AppModule {}
My system information:
Cordova CLI:6.3.1
Ionic Framework版本:2.0.0-rc.1
Ionic CLI版本:2.1.1
Ionic App Lib版本:2.1.1
Ionic App Scripts版本:0.0.36
操作系统:分销商ID:Ubuntu描述:Ubuntu 16.04.1 LTS
节点版本:v4.2.6
1 回答
我有同样的问题,也许我有一个解决方案(适合我) .
我已经从我的app.components.ts中完全删除了firebase初始化,并在app.module.ts中将其添加到NGModule之前,例如:
现在我可以在我的服务中使用它(不要忘记将你的服务包含在app.module.ts的提供者中:[yourService]')
希望这对你有用!