I am try to connect to database in firebase. Here is the 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 {}
The error is in this line
import { AngularFireDatabase, AngularFireDatabaseModule } from 'angularfire2/database';
I have tried this also import { AngularFireDatabase, AngularFireDatabaseModule } from 'angularfire2/database-deprecated';
But the the error just change.
Runtime Error Cannot find module "angularfire2/database" Stack Error: Cannot find module "angularfire2/database" at Object.217 (http://localhost:8100/build/main.js:78:7) at webpack_require (http://localhost:8100/build/vendor.js:55:30) at Object.194 (http://localhost:8100/build/main.js:60:70) at webpack_require (http://localhost:8100/build/vendor.js:55:30) at webpackJsonpCallback (http://localhost:8100/build/vendor.js:26:23) at http://localhost:8100/build/main.js:1:1
Just read this documentation
in terminal: npm install firebase --save
In your app.module.ts create firebase config object:
// 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();
After the call on Page .ts:
import * as firebase from 'firebase';