【问题标题】:Angular 2+ CRUD Operations With Firebase 5.0Firebase 5.0 的 Angular 2+ CRUD 操作
【发布时间】:2018-07-10 01:08:46
【问题描述】:
【问题讨论】:
标签:
angular
firebase-realtime-database
angular2-services
angularfire5
【解决方案1】:
`
//providers/person.ts
import { Injectable } from '@angular/core';
import {AngularFireDatabase} from 'angularfire2/database';
import {Person} from './Person.ts';
@Injectable()
export class PersonProvider {
private personListRef = this.db.list<Person>('persons');
constructor(private db: AngularFireDatabase) {}
/**
* Creates Person
*/
createPerson(person: Person) {
return this.personListRef.push(person);
}
/**
* Reads Persons
*/
getPersons() {
return this.personListRef;
}
/**
* Updates Person
*/
updatePerson(person: Person) {
return this.personListRef.update(person.key, person);
}
/**
* Deletes Person
*/
deletePerson(person: Person) {
return this.personListRef.remove(person.key);
}
}
`
根据您使用的 AngularFire2 版本(使用 5.0.0-rc.11 测试),您可能需要安装 rxjs@6。
npm install rxjs@6 rxjs-compat@6 --save