I'm learning Firebase and Angular4 and am using AngularFire2.
I have a list of items with a custom key and I have a list of owners, also with a custom key in a firebase db.
I first joined the item with his owner by using its key in the item and when retrieving the item I would do a second request to get the data of the owner.
I understand that this is not the way to handle this in a NoSQL database, it is better to save the whole owner object as a child in my item. Then I would not need to get the owner detail separately.
I have a form to edit the item data, which has a select box with all the owners. This list of owners is retrieved in ngOnInit. The selectbox is populated as:
<select class="form-control" formControlName="owner" id="owner">
<option *ngFor="let ownerList of owners" [value]="ownerList">
{{ownerList.name}}
</option>
</select>
I'm not sure if I create this select box correctly, but it seems to be working.
OnSubmit I do:
updateItem(alias: string, formValues: Item) {
const mergedUpdate = {};
mergedUpdate[ "item/" + alias] = formValues;
this.af.database.ref().update(mergedUpdate);
}
When I now look at how the data is saved in the firebase console I see for owner [object Object]
I've been reading numerous posts but can't figure out what I'm doing wrong. Please advice.