What's the difference between AngularFireDatab

2019-08-28 10:06发布

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条回答
姐就是有狂的资本
2楼-- · 2019-08-28 10:36

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
  }
}
查看更多
登录 后发表回答