This is my first project in Angular4 + Firebase, I would like your support about some questions. I'm using AngularFire2 to connect with Firebase server.
This is my Firebase database:
product
|-KmlWSH-U3XTwudPsA4X
|name: "product 1"
|type: "52"
|manufacture: "-KtJkcbXP5dOcOeoP20G"
|-KmlXXX-XXXXXX
|name: "product 2"
|type: "53"
|manufacture: "-XXXXXXXXXXXXXXXXXX"
manufacture
|-KtJkcbXP5dOcOeoP20G
|name: "manufacture 1"
|country: "Japan"
I'm trying to get a list of products joined with the properly manufacture object. I expect to receive something like this:
{$key: -KmlWSH-U3XTwudPsA4X
name: "product 1"
type: "52"
manufacture: "-KtJkcbXP5dOcOeoP20G"
manufactureObject: {name: "manufacture 1", country: "Japan"} }
Currently I'm using the follow code to retrieve this:
return this.db.list("product")
.map(products => products.map(product => {
let p = Product.fromJson(product);
p.manufactureObject = this.db.object("manufacture"+ "/" +p.manufacture);
return p;
}))
"manufactureObject" returns as Observable in this case.
On the template I have no problem with that, I'm using
{{ (row.manufactureObject | async)?.name}}
Works like a charm.
But I'm don't know how to use it on FormGroup.
this.form = new FormGroup({
'$key': new FormControl(t.$key),
'name': new FormControl(t.name, Validators.required),
'manufactureObject': new FormControl(t.manufactureObject, Validators.required),
});
Has anyone know how to do it? Is there any other way to do it?
In SQL this is so simple, it is just a "join" with another table ^^
Thanks for your support