node_modules / angularfire2 /数据库/索引"'没有导出的成员' AngularFireList'

时间:2017-11-30 07:29:25

标签: angular firebase-realtime-database angularfire2

我正在尝试从AngularFireList导入angularfire2/database但是收到此错误:node_modules / angularfire2 / database / index没有导出的成员AngularFireList

我使用的是angularfire2版本^ 5.0.0-rc.0

以下是代码:

import { Component } from '@angular/core';
import { AngularFireDatabase, AngularFireList } from 
'angularfire2/database';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

@Component({
  selector: 'app-root',
  template: `
 <ul>
    <li *ngFor="let item of items | async">
      <input type="text" #updatetext [value]="item.text" />
      <button (click)="updateItem(item.key, 
updatetext.value)">Update</button>
      <button (click)="deleteItem(item.key)">Delete</button>
    </li>
  </ul>
 <input type="text" #newitem />
  <button (click)="addItem(newitem.value)">Add</button>
  <button (click)="deleteEverything()">Delete All</button>
  `,
})
export class AppComponent {
  itemsRef: AngularFireList<any>;
  items: Observable<any[]>;
  constructor(db: AngularFireDatabase) {
    this.itemsRef = db.list('messages');

    this.items = this.itemsRef.snapshotChanges().map(changes => {
      return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
    });
  }
  addItem(newName: string) {
    this.itemsRef.push({ text: newName });
  }
  updateItem(key: string, newText: string) {
    this.itemsRef.update(key, { text: newText });
  }
  deleteItem(key: string) {    
    this.itemsRef.remove(key); 
  }
  deleteEverything() {
    this.itemsRef.remove();
  }
    }

1 个答案:

答案 0 :(得分:0)

不是 FirebaseObjectObservable AngularFireObject FirebaseListObservable AngularFireList 的。

import { AngularFireObject, AngularFireList } from 'angularfire2/database';

检查migration guide(almothafar,github)