所以我尝试了Josh Morony关于如何在Ionic中处理Firebase的教程: https://www.joshmorony.com/building-a-crud-ionic-2-application-with-firebase-angularfire/
到目前为止我做了什么:
app.module.ts
AngularFireDatabaseModule
并在imports
。 import { AngularFireDatabaseModule } from 'angularfire2/database';
imports: [
BrowserModule,
AngularFireModule.initializeApp(config),
AngularFireDatabaseModule
career.ts
AngularFireDatabase, AngularFireList
,在AngularFireDatabase
中注入了constructor
。 import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';
constructor(public navCtrl: NavController, private database: AngularFireDatabase)
答案 0 :(得分:5)
在AngularFire2中,有两种要注意的Object类型。
this.database.list('/company')
的类型为AngularFireList<any>
this.database.list('/company').valueChanges()
提供Observable<any[]>
。
如果您需要对两者的引用,您可以执行以下操作:
this.companiesRef:AngularFireList<any>;
this.companies:Observable<any[]>;
//...
//while accessing,
this.companiesRef = this.database.list('/company');
this.companies = this.companiesRef.valueChanges();
参考文档here