spl*_*unk 3 firebase typescript ionic-framework ionic2 angular
我正在使用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();
});
}
}
Run Code Online (Sandbox Code Playgroud)
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 {}
Run Code Online (Sandbox Code Playgroud)
我的系统信息:
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
我有同样的问题,也许我有一个解决方案(适合我).
我已经从我的app.components.ts中完全删除了firebase初始化,并在app.module.ts中将其添加到NGModule之前,例如:
...
import * as firebase from 'firebase';
export const firebaseConfig = {
apiKey: "",
authDomain: ".firebaseapp.com",
databaseURL: "https://.firebaseio.com",
storageBucket: ".appspot.com",
messagingSenderId: ""
};
firebase.initializeApp(firebaseConfig); //<-- where the magic happens
@NgModule({
...
Run Code Online (Sandbox Code Playgroud)
现在我可以在我的服务中使用它(不要忘记将你的服务包含在app.module.ts的提供者中:[yourService]')
import firebase from 'firebase';
@Injectable()
export class yourService {
//Here you can use firebase.database(); or firebase.auth(); as you wish and it should work.
}
Run Code Online (Sandbox Code Playgroud)
希望这对你有用!
| 归档时间: |
|
| 查看次数: |
2557 次 |
| 最近记录: |