我正在尝试从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();
}
}
答案 0 :(得分:0)
不是 FirebaseObjectObservable 的 AngularFireObject 和 FirebaseListObservable 的 AngularFireList 的。
import { AngularFireObject, AngularFireList } from 'angularfire2/database';
检查migration guide(almothafar,github)