Issue
Is there any way to fetch data (by id) at obj obj ?
example:
hello(){
this._shelveService.getShelveDataById(this.route.snapshot.params.id).subscribe(data => {
console.log(data);
this._shelveForm = this.fb.group({
id_shelve:[data['id_shelve']],
description_shelve:[data['description_shelve']],
war_id:this.fb.group({
id_warehouse: [data['war_id.id_warehouse']]
})
})
})
}
how to get the value of id_warehouse ?
I can get the value id_shelve and description_shelve with the hello() function but if I type:
war_id:this.fb.group({
id_warehouse: [data['war_id']]
i get as a result Obj Ojb
json :
{
"id_shelve": 1,
"description_shelve": "Περιγράφη Ραφίου!!!",
"war_id": {
"id_warehouse": 1,
"description_warehouse": "Περιγράφη Αποθήκης!!!"
}
}
Any help;
Solution
You can solve this by either of the two approaches below:
a) Dot notation:
this._shelveForm = this.fb.group({
id_shelve: [data['id_shelve']],
description_shelve: [data['description_shelve']],
war_id: this.fb.group({
id_warehouse: [data.war_id.id_warehouse],
description_warehouse: [data.war_id.description_warehouse]
})
});
b) Square bracket notation:
this._shelveForm = this.fb.group({
id_shelve: [data['id_shelve']],
description_shelve: [data['description_shelve']],
war_id: this.fb.group({
id_warehouse: [data['war_id']['id_warehouse']],
description_warehouse: [data['war_id']['description_warehouse']]
})
});
Answered By – mikeandtherest
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0