【问题标题】:Angular 2+ CRUD Operations With Firebase 5.0Firebase 5.0 的 Angular 2+ CRUD 操作
【发布时间】:2018-07-10 01:08:46
【问题描述】:

我已经意识到 firebase 5.0 的操作与以前的版本 https://github.com/angular/angularfire2/blob/master/docs/version-5-upgrade.md 不同。请帮助我提供一个角度服务,该服务基本上使用此界面在 firebase 实时数据库上执行 CRUD

//Person.ts
interface Person{
    $id :string;
    name: string;
    age: string;
    gender: string;
}

【问题讨论】:

    标签: 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-17
      • 2016-10-25
      • 2017-09-10
      • 2017-04-07
      • 2013-10-27
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      相关资源
      最近更新 更多