Ionic 中的 AngularFireDatabaseModule 和 AngularFireDatabase 有什么区别? [英] What's the difference between AngularFireDatabaseModule and AngularFireDatabase in Ionic?

查看:23
本文介绍了Ionic 中的 AngularFireDatabaseModule 和 AngularFireDatabase 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Angularfire2 Docs,它说;AngularFireDatabase 允许您使用 Firebase 的原始数据库实时数据库.对于需要跨客户端实时同步状态的移动应用,这是一种高效、低延迟的解决方案.

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.

然而,有AngularFireDatabaseModule,我不知道它是什么.因此,我想更详细地了解这两个是什么(如果可用,请提供更详细的链接)以及何时使用 AngularFireDatabaseAngularFireDatabaseModule.

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.

推荐答案

AngularFireDatabaseModule 是您需要在 中导入到 @ngModule 中的模块声明app.module.

AngularFireDatabaseModule is the module declaration that you need to import into your @ngModule in your app.module.

AngularFireDatabase 允许您使用实时数据库并可以注入到组件中.

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
  }
}

这篇关于Ionic 中的 AngularFireDatabaseModule 和 AngularFireDatabase 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆