我已经成功地更新了angularfire 5.0.0.rc8和firebase 5.0.2,没有错误模块。我想我要做的最后一件事就是修改这个代码来检索所有数据。
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { IonicPage } from 'ionic-angular/navigation/ionic-page';
import { Observable } from 'rxjs';
import 'rxjs/add/operator/map';
import { Note } from '../../model/note/note.model';
import { NoteListService } from '../../services/note-list.service';
@IonicPage()
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
noteList: Observable<Note[]>
constructor(public navCtrl: NavController, private noteListService: NoteListService) {
this.noteList = this.noteListService.getNoteList()
.snapshotChanges()
.map(
changes => {
return changes.map(c => ({
key: c.payload.key, ...c.payload.val()
}))
});
}
}noteListService文件..。
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Note } from '../model/note/note.model';
@Injectable()
export class NoteListService {
private noteListRef = this.db.list<Note>('note-list');
constructor(private db: AngularFireDatabase) { }
getNoteList() {
return this.noteListRef;
}
addNote(note: Note) {
return this.noteListRef.push(note);
}
updateNote(note: Note) {
return this.noteListRef.update(note.key, note);
}
removeNote(note: Note) {
return this.noteListRef.remove(note.key);
}
}帮助更改此代码,该代码将与我的新版本angularfire 5.0.0 rc 8和firebase 5.0.2兼容
这是一个新的错误后,我的一半的代码正在工作。插入零件。但我还是无法质疑
运行时错误隐藏(承诺):this.noteListService.getNoteList(...).snapshotChanges(...).map不是TypeError A function TypeError: TypeError不是在createClass (http://localhost:8100/build/vendor.js:10575:20) at createDirectiveInstance (http://localhost:8100/build/vendor.js:10458:20) at createViewNodes (http://localhost:8100/build/vendor.js:11680:36) at createRootView (http://localhost:8100/build/vendor.js:11594:5) at callWithDebugContext (http://localhost:8100/build/vendor.js:12629:25) at Object.debugCreateRootView as createRootView at ComponentFactory_.create (http://localhost:8100/build/vendor.js:12629:25) at ComponentFactory_.create() at (http://localhost:8100/build/vendor.js:49286:44 )处的新HomePage (http://localhost:8100/build/0.js:86:14)的函数)堆栈错误: Uncaught (为了承诺):this.noteListService.getNoteList(...).snapshotChanges(...).map不是一个函数
发布于 2018-05-19 05:03:37
新版本angularfire v5.0.0-rc.9每样东西都很好。
这是从firebase检索数据的代码。
import { Component, Injectable } from '@angular/core';
/*import { NavController } from 'ionic-angular';*/
import { IonicPage } from 'ionic-angular/navigation/ionic-page';
import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Note } from '../../model/note/note.model';
@Injectable()
@IonicPage()
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
itemsRef: AngularFireList<any>;
items: Observable<Note[]>;
constructor(db: AngularFireDatabase) {
this.itemsRef = db.list('note-list');
this.items = this.itemsRef.snapshotChanges().pipe(
map(changes =>
changes.map(c => ({ key: c.payload.key, ...c.payload.val() }))
)
);
}
}https://github.com/bnayak0225/Biswajit-Note-Ionic-Firebase-angularfire2-5.0.0-rc-9
发布于 2018-05-17 23:04:03
您还没有正确地从rxjs导入map操作符,而且在rxjs 6中还需要使用pipe。
...
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@IonicPage()
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
noteList: Observable<Note[]>
constructor(public navCtrl: NavController, private noteListService: NoteListService) {
this.noteList = this.noteListService.getNoteList()
.snapshotChanges()
.pipe(
map(changes =>
changes.map(c => ({
key: c.payload.key, ...c.payload.val()
}))
})
);
}
}https://stackoverflow.com/questions/50387987
复制相似问题