how to get a particular object value from nested json array

Bhavith .V.N

CategoryComponent.html:57 ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'Samsung'. NgFor only supports binding to Iterables such as Arrays. I can only display the product array rest it is not working with this code

This is the error I am getting in the console

 <mat-accordion multi="true"  *ngFor="let item1 of products">
      <mat-expansion-panel  *ngFor="let item2 of item1.childcat">
        <mat-expansion-panel-header *ngFor="let item3 of item2.subcat">
          {{item2.name}}{{ item3.name}}
        </mat-expansion-panel-header>
        <p>HAlo</p>
      </mat-expansion-panel>
    </mat-accordion> <!-- filter-group  .// -->

My Component

 this.route.queryParams.subscribe(params => {
 this.categoryService.getProduct().subscribe(products => this.products = products) 

Service file

 getProduct(): Observable<Product[]>{
let params_url = new HttpParams().set('fil_outlet',this.name);
console.log('new my ss--',this.name);
return this.http.get<Product[]>("http://localhost:4500/products",{params:params_url});

};

JSON

[
{
    "id": 1,
    "name": "A7",
    "childcatId": "1",
    "subcatId": "1",
    "price": 18000,
    "mrp": 21000,
    "discription": "sfhshsfhsf",
    "image": "http://bestjquery.com/tutorial/product-grid/demo3/images/img-7.jpeg",
    "createdAt": "2019-11-13T00:00:00.000Z",
    "updatedAt": "2019-11-14T02:00:00.000Z",
    "childcat": {
        "id": 1,
        "name": "samsung",
        "categoryId": "1",
        "subcatId": "1",
        "createdAt": "2019-11-21T00:00:00.000Z",
        "updatedAt": "2019-11-21T00:00:00.000Z",
        "subcat": {
            "id": 1,
            "name": "Mobile",
            "categoryId": "1",
            "createdAt": "2019-11-19T00:00:00.000Z",
            "updatedAt": "2019-11-05T00:00:00.000Z",
            "filter_groups": [
                {
                    "id": 1,
                    "name": "Ram",
                    "subcatId": "1",
                    "createdAt": "2019-11-13T00:00:00.000Z",
                    "updatedAt": "2019-11-13T00:00:00.000Z",
                    "filters": [
                        {
                            "id": 1,
                            "name": "2 GB",
                            "filterGroupId": "1",
                            "productId": "1",
                            "createdAt": "2019-11-19T00:00:00.000Z",
                            "updatedAt": "2019-11-27T00:00:00.000Z"
                        }
                    ]
                },
                {
                    "id": 2,
                    "name": "Internal Storage",
                    "subcatId": "1",
                    "createdAt": "2019-11-05T00:00:00.000Z",
                    "updatedAt": "2019-11-24T00:00:00.000Z",
                    "filters": [
                        {
                            "id": 2,
                            "name": "8 GB",
                            "filterGroupId": "2",
                            "productId": "1",
                            "createdAt": "2019-11-20T00:00:00.000Z",
                            "updatedAt": "2019-11-20T00:00:00.000Z"
                        }
                    ]
                }
            ]
        }
    }
}

]

Christopher Coleman

You are attempting to call an *ngFor on objects, not arrays. What you do instead is simply call the items themselves. See the following code.

 <mat-accordion multi="true">
      <mat-expansion-panel  *ngFor="let item1 of products">
        <mat-expansion-panel-header>
          {{item1.childcat.name}}{{ item1.childcat.subcat.name}}
        </mat-expansion-panel-header>
        <p>HAlo</p>
      </mat-expansion-panel>
    </mat-accordion> <!-- filter-group  .// -->

If you have the potential to have a null childcat, then you can modify the code slightly with an ngIf.

<mat-accordion multi="true">
  <mat-expansion-panel  *ngFor="let item1 of arrObject">
    <mat-expansion-panel-header>
      <p *ngIf="item1.childcat">{{item1.childcat.name}}{{ item1.childcat.subcat.name}}</p>
    </mat-expansion-panel-header>
    <p>HAlo</p>
  </mat-expansion-panel>
</mat-accordion> <!-- filter-group  .// -->

You don't necessarily have to use a p tag for this but just some sort of wrapper that uses the if. Keep in mind that if the subcat within your childcat has the potential to be null you will have to do a check for that as well. (Not shown)

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

get value from nested json array

分類Dev

jQuery - How to get JSON array name from nested JSON

分類Dev

How can I get the key name and its value from an array within a JSON object

分類Dev

How can I get a specific value from my JSON object without using Array.filter()?

分類Dev

How to get particular data from json object passing id in Angular 7

分類Dev

ExpressJS Fetching value from nested JSON Object

分類Dev

How to get json value from json array using javascript

分類Dev

Get Nested value from JSON response with python

分類Dev

How to get a particular attribute from an array of array objects?

分類Dev

How to get a name value from a foreign key of a Json object

分類Dev

JQgrid - cannot get output from Json where value of array is Object, Object

分類Dev

How to get particular hashmap keys and values from json objects

分類Dev

Get the object with the lowest value attribute from array

分類Dev

Get object value from array in cache laravel

分類Dev

get index from a JSON object with value

分類Dev

Get value from json object with javascript

分類Dev

How to take a value from nested array(json format) without using multiple foreach in php

分類Dev

Get JSON value from API array

分類Dev

$.ajax get an object after json_encode($arr) from php, but how to get key and value in jQuery?

分類Dev

How to get a json object with specific key values, from a json array column?

分類Dev

In jsonpath how to put new value for nested json object?

分類Dev

How to get the correct object in an nested array in Vue.js?

分類Dev

How to get inner array of nested object using underscorejs?

分類Dev

How to get the combination of array values from nested arrays in an array of objects

分類Dev

Extracting a particular value from a JSON file

分類Dev

How do I extract a specific object from a nested array?

分類Dev

How to get values from Deserialized JSON object?

分類Dev

How to get all Object from Json to List

分類Dev

How to find the random value for a particular string in an array

Related 関連記事

  1. 1

    get value from nested json array

  2. 2

    jQuery - How to get JSON array name from nested JSON

  3. 3

    How can I get the key name and its value from an array within a JSON object

  4. 4

    How can I get a specific value from my JSON object without using Array.filter()?

  5. 5

    How to get particular data from json object passing id in Angular 7

  6. 6

    ExpressJS Fetching value from nested JSON Object

  7. 7

    How to get json value from json array using javascript

  8. 8

    Get Nested value from JSON response with python

  9. 9

    How to get a particular attribute from an array of array objects?

  10. 10

    How to get a name value from a foreign key of a Json object

  11. 11

    JQgrid - cannot get output from Json where value of array is Object, Object

  12. 12

    How to get particular hashmap keys and values from json objects

  13. 13

    Get the object with the lowest value attribute from array

  14. 14

    Get object value from array in cache laravel

  15. 15

    get index from a JSON object with value

  16. 16

    Get value from json object with javascript

  17. 17

    How to take a value from nested array(json format) without using multiple foreach in php

  18. 18

    Get JSON value from API array

  19. 19

    $.ajax get an object after json_encode($arr) from php, but how to get key and value in jQuery?

  20. 20

    How to get a json object with specific key values, from a json array column?

  21. 21

    In jsonpath how to put new value for nested json object?

  22. 22

    How to get the correct object in an nested array in Vue.js?

  23. 23

    How to get inner array of nested object using underscorejs?

  24. 24

    How to get the combination of array values from nested arrays in an array of objects

  25. 25

    Extracting a particular value from a JSON file

  26. 26

    How do I extract a specific object from a nested array?

  27. 27

    How to get values from Deserialized JSON object?

  28. 28

    How to get all Object from Json to List

  29. 29

    How to find the random value for a particular string in an array

ホットタグ

アーカイブ