You might think, we can re-factor the onChange()
method, so it can differentiate between checked and un-checked items and save only selected news. That might solve a part of the issue, but the main problem (objects being overwritten) still exists.
The solution relies on another AngularFire object called FirebaseListObservable
. With the list objects we can push entries without losing the previous objects. In our previous example, we updated the code and replaced the object.set()
method with the list.push()
method as follows:
// src/app/collector/collector.component.ts //... import {AngularFire, FirebaseListObservable} from "angularfire2/angularfire2"; //... export class CollectorComponent { //... constructor (collectorService: CollectorService, af: AngularFire) { //... this.items = af.database.list('/Collector'); } onChange(item){ this.items.push(item); } }
Now inside the collector page, select a few news entries from the collected...