Right now, I am unwrapping my data using the method described in the documentation. However, the documentation states:
AngularFire2 unwraps the Firebase DataSnapshot by default, but you can get the data as the original snapshot by specifying the preserveSnapshot option.
How would I be able to access the "default" unwrapping functionality (read: access the elements of item) without having the manually unwrap the data snapshot?
My data from Firebase looks like this:
{
testObj : {
firstName: "beckah",
lastName: "s"
}
}
My code (which works) is:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AngularFireDatabase, FirebaseObjectObservable } from 'angularfire2/database';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
item: FirebaseObjectObservable<any>;
constructor( public navCtrl: NavController,
public db: AngularFireDatabase ) {
this.item = db.object('/testObj', { preserveSnapshot: true });
this.item.subscribe(snapshot => {
console.log(snapshot.val())
});
}
}
Which outputs
Object {firstName: "beckah", lastName: "s"}
How would I be able to do the exact same thing (console.log my item object) without manually unwrapping my snapshot like the documentation states is possible?
Is there some kind of this.item.get("firstName") method?