import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Note } from '../../model/note';
import { NoteListService } from '../../services/note-list.service';
@IonicPage()
@Component({
selector: 'page-edit-note',
templateUrl: 'edit-note.html',
})
export class EditNotePage {
note: Note = {
key: '',
title: '',
content: ''
};
constructor(
public navCtrl: NavController,
public navParams: NavParams,
private noteListService: NoteListService) {
}
ionViewDidLoad() {
this.note = this.navParams.get('note');
}
updateNote(note: Note) {
this.noteListService.updateNote(note).then(() => {
this.navCtrl.setRoot('MeuCadastroPage');
})
}
removeNote(note: Note) {
this.noteListService.removeNote(note).then(() => {
this.navCtrl.setRoot('MeuCadastroPage');
})
}
}
My note-list-service.ts:
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Note } from '../model/note';
@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);
}
}
My error: ''Reference.child failed: First argument was an invalid path = " . paths must be non empty.