What's the difference between AngularFireDatabaseModule and AngularFireDatabase in Ionic?

◇◆丶佛笑我妖孽 提交于 2019-12-11 16:18:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!