0

I have a data structure that looks like this:

app_list = ["app_1", "app_2"]
data["results"] =
{
    "app_1": [
        {"key":1},
        {"key":2}
    ],
    "app_2": [
        {"key":1},
        {"key":2}
    ],
}

And would like to display it with this html code:

<div *ngFor="let app of app_list" >
    {{app}}
    <pre>
        {{data?.results?.app | json}} #This line
    </pre>
    <div *ngFor="let item of data.results.app">
        {{item}}
    </div>
</div>

But the json object I have set as "This line" seems to not render anything. This also means that the subsequent ngfor loop also does nothing. Am I doing something wrong here?

Whats a better way to do this?

2
  • What is the value of results ? you should probably write data["results"] =... Commented Mar 31, 2021 at 19:33
  • editted. I missed the " it seems there. Not in my code though, just in the post as I typed it manually. Commented Apr 1, 2021 at 17:35

1 Answer 1

3

It should be something like this:

<div *ngFor="let app of app_list" >
        {{app}}
        <pre>
            {{data?.results[app] | json}} #This line
        </pre>
        <div *ngFor="let item of data.results[app]">
            {{item}}
        </div>
    </div>
Sign up to request clarification or add additional context in comments.

5 Comments

Hey that worked! I tried it the first time and it failed.. I might have had a typo somewhere. Thanks!
@ScipioAfricanus great! can you please mark it as the correct answer
Yeah there is a cool down I have to wait a bit
@ScipioAfricanus just out of curiosity, what's a cool down ?
hmm not sure, 1 hour or so I think.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.