问题
According to Angularfire2 Docs, it says that;
AngularFireDatabase
allows you to work with the Realtime Database, Firebase's original database. It's an efficient, low-latency solution for mobile apps that require synced states across clients in realtime.
However, There is AngularFireDatabaseModule
, which I have no idea what is it. Therefore, I wanted to know what are these two in more detail (provide a more detailed link if available) and when to use AngularFireDatabase
and AngularFireDatabaseModule
.
回答1:
AngularFireDatabaseModule
is the module declaration that you need to import into your @ngModule
in your app.module
.
AngularFireDatabase
allows you to work with the realtime database and can be injected into components.
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AngularFireModule.initializeApp({}),
AngularFireDatabaseModule
],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts:
import { Component } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
@Component({
selector: 'app-root',
template: ``,
styles: []
})
export class AppComponent {
constructor(
private readonly afDatabase: AngularFireDatabase
) {
// can make calls against this.afDatabase in this class
}
}
来源:https://stackoverflow.com/questions/50313801/whats-the-difference-between-angularfiredatabasemodule-and-angularfiredatabase