Hello! I am working with the firebase databank and I want to get the information from it. The push operation works fine.
I have the following error:
Type ‘Observable<any[]>’ is not assignable to type ‘Observable<Note[]>’. Types of property ‘subscribe’ are incompatible. Type ‘{ (): Subscription; (observer: PartialObserver<any[]>): Subscription; (next?: (value: any[]) => v…’ is not assignable to type ‘Subscribe<Note[]>’. Type ‘Subscription’ is not assignable to type ‘Unsubscribe’. Type ‘Subscription’ provides no match for the signature ‘(): void’.
The weirdest thing about it is that when I save my code again and restart the application it works perfectly fine but still have the error message in my visual studio. The problem is at the line with “this.dataList$ = this.noteService…”. It says that a typ Observable can’t be assigned to Observable .
Home.ts File:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AddNotePage } from '../add-note/add-note';
import { NoteService } from '../../providers/note-service/note-service';
import { Note } from '../../models/note.model';
import { ViewNotePage } from '../view-note/view-note';
import { AngularFireList } from 'angularfire2/database';
import { AngularFireObject } from 'angularfire2/database';
import { Observable } from '@firebase/util';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
//private notes : Promise<Note[]>;
//private note: Note;
dataList$: Observable<Note[]>;
//data: AngularFireObject<any>;
constructor(public navCtrl: NavController, private noteService: NoteService) {
this.dataList$ = this.noteService.getAllNotes().snapshotChanges().map(
changes => {
return changes.map(c => ({
key: c.payload.key, ...c.payload.val()
}))
})
}
ionViewWillEnter() {
/**this.data = this.noteService.getAllNotes();
console.log(this.data.valueChanges())
console.log("rge3")*/
}
addNote() {
this.navCtrl.push(AddNotePage);
}
getNote(createDate: number) {
/**
this.noteService.getNote(createDate).then((n) => {
this.note = n;
this.navCtrl.push(ViewNotePage, { note: this.note })
})
*/
}
getAllNotes() {
return this.noteService.getAllNotes();
}
}
note-service.ts File:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';
import { Note } from '../../models/note.model';
import { AngularFireDatabase } from 'angularfire2/database';
@Injectable()
export class NoteService {
//private notes: Note[] = [];
//private note: Note;
private dataRef = this.fdb.list<Note>('/mydata/');
constructor(public storage: Storage, private fdb: AngularFireDatabase) {
}
saveNote(note: Note) {
note.createDate = Date.now();
//this.notes.push(note);
//this.storage.set('notes', this.notes);
this.dataRef.push(note);
}
getAllNotes() {
console.log("gfvdf")
return this.dataRef;
/**
return this.storage.get('notes').then(
(notes) => {
this.notes = notes == null ? [] : notes;
return [...this.notes];
})
*/
}
getNote(createDate: number) {
/**
return this.storage.get('notes').then((notes) => {
this.note = [...notes].find(r => r.createDate === createDate);
return this.note;
});
*/
//return this.fdb.list('/mydata/');
}
/**
deleteNote(createDate: number) {
this.notes = this.notes.filter((note) => {
return note.createDate !== createDate
});
//this.storage.set('notes', this.notes);
}*/
}
Thank you for the help!