So far I've been able to migrate my CRUD app to Firebase. I can list, create and delete news. I'm struggling with edit though.
This is the edit component. It takes a snapshot of the route params which is equal to the $key value of that particular news in Firebase. Then I concatenate it to the database listing:
import { Component} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AngularFire, FirebaseListObservable } from 'angularfire2';
@Component({
moduleId: module.id,
selector: 'app-edit-news',
templateUrl: 'edit-news.component.html',
styleUrls: ['edit-news.component.css']
})
export class EditNewsComponent {
noticia: FirebaseListObservable<any>;
constructor(
private route: ActivatedRoute,
private af: AngularFire) {
this.news = af.database.list('news/'+this.route.snapshot.params['id']);
}
}
I'm new to observables but I thought with this I could be able to access the concrete object of the database using interpolation such us {{news.title}} Obviously, I'm wrong. Any help?
[(ngModel)]="news.foo"and you can edit them and save the changes. The interpolation I mentioned was just an example of accessing the values.