问题描述
Angularfire2文档表示: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
,我不知道它是什么.因此,我想知道这两个的详细信息(如果可用,请提供更详细的链接)以及何时使用AngularFireDatabase
和AngularFireDatabaseModule
.
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
是您需要导入到app.module
中@ngModule
中的模块声明.
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有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!