我尝试连接到firebase中的数据库。这是app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { AngularFireDatabase, AngularFireDatabaseModule } from 'angularfire2/database';
import { AngularFireModule } from 'angularfire2';
import { environment } from '../environments/environment';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
AngularFireModule.initializeApp(environment.firebase),
AngularFireDatabaseModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
AngularFireDatabase,
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
错误在此行
import { AngularFireDatabase, AngularFireDatabaseModule } from 'angularfire2/database';
我也试过这个 从{angularfire2 / 数据库已弃用 ';
导入{AngularFireDatabase,AngularFireDatabaseModule}但错误只是改变了。
运行时错误无法找到模块" angularfire2 / database"堆栈错误: 找不到模块" angularfire2 / database" 在Object.217(http://localhost:8100/build/main.js:78:7) 在 webpack_require (http://localhost:8100/build/vendor.js:55:30) 在Object.194(http://localhost:8100/build/main.js:60:70) 在 webpack_require (http://localhost:8100/build/vendor.js:55:30) 在webpackJsonpCallback(http://localhost:8100/build/vendor.js:26:23) 在http://localhost:8100/build/main.js:1:1
答案 0 :(得分:1)
请阅读此documentation
终端中的:npm install firebase --save
在你的app.module.ts中创建firebase配置对象:
// Set the configuration for your app
// TODO: Replace with your project's config object
var config = {
apiKey: "apiKey",
authDomain: "projectId.firebaseapp.com",
databaseURL: "https://databaseName.firebaseio.com",
storageBucket: "bucket.appspot.com"
};
firebase.initializeApp(config);
// Get a reference to the database service
var database = firebase.database();
在Page .ts上调用后:
import * as firebase from 'firebase';
答案 1 :(得分:0)
"angularfire2": "^5.0.0-rc.10"
有问题
对我来说,解决方案是卸载angularfire2^5.0.0-rc.10
和install angularfire2^5.0.0-rc.9
npm uninstall angularfire2
npm install angularfire2@5.0.0-rc.9
我确认这项工作有效,@ jsariasgeek提供的解决方案