0

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;

3
  • Could you please clarify the question, and what do you expect to get exactly?
    – Amer
    Aug 28, 2021 at 14:04
  • @AmerYousuf i change it please help me :) Aug 28, 2021 at 14:18
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Aug 31, 2021 at 6:23

2 Answers 2

0

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']]
    })
});
2
  • you are a truly legend i was dealing with this issue about 5 hours,I'm so noob :( Aug 28, 2021 at 15:05
  • Being a newbie/noob is not a bad thing, as long as you're a constant learner! Btw, there are certain situations in which what you tried to do initially might have sense. For eg if one of the fields inside the JSON data contains a dot in its name. For more details over this, you can refer to this answer: stackoverflow.com/a/4968448/5780536 Aug 28, 2021 at 15:09
0

Replace:

war_id:this.fb.group({
  id_warehouse: [data['war_id']] 

with

war_id:this.fb.group({
  id_warehouse: [data['war_id']['id_warehouse']] 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.