#Nested ngFor
29 messages · Page 1 of 1 (latest)
what's the problem? do you have an error? you don't see anything?
what code gets rendered if you inspect the browser window?
Yeah nothing is showing up
what code gets rendered if you inspect the browser window?
Nothing gets rendered
if nothing gets rendered, either you app is completely broken, or you have no categories.
try to make the first for work, ignoring what's inside
I can get it to render the last post with this:
It's just when I try to get the last post of category.posts it's just blank in the browser
I know i'm not explaining this very well
here you are using posts in the first example you are using categories
if NOTHING gets rendered, it means that categories is an empty array. Otherways you should see some <div> when you inspect the code
would be good if you share the code on Stackblitz
This is the div that i'm seeing in the console
ok something gets rendered, but it's hard to say what.
- Please do 2 things: add class="test-category" to the first
*ngFor - add this in your code: {{categories | json}}
then show what code gets rendered when you inspect your window
It's rendering the json for all of the categories
6 times because there are 6 categories
copy/paste it here 🙂
[ { "id": 1, "name": "Gaming Forum", "description": "The latest video game news, discussions, announcements, industry gossip, sales figures, bargains and reviews. The pulse of the gaming industry.", "createdAt": "2023-03-04T03:35:22", "status": "active", "viewCount": 0, "postCount": 1, "commentCount": 1, "enabled": true }, { "id": 2, "name": "Gaming Hangouts", "description": "If it's a community related to gaming, it has a home here! Official threads >1 month old, buy/sell/trade marketplace, gaming media fandoms, matchmaking, guilds and clans.", "createdAt": "2023-03-04T03:35:22", "status": "active", "viewCount": 0, "postCount": 1, "commentCount": 1, "enabled": true }, { "id": 3, "name": "Lore Forum", "description": "Everything else. Current events, entertainment, technology, life, food, politics, pets, randomness, and anything in between. Civil discourse triumphs.", "createdAt": "2023-03-04T03:35:22", "status": "active", "viewCount": 0, "postCount": 1, "commentCount": 1, "enabled": true }, { "id": 4, "name": "Lore Hangouts", "description": "Hobbyist enclaves. Sports followings. Official threads >1 month old. Local, international, and non-English language threads. Whatever your passion, find a community to share it with!", "createdAt": "2023-03-04T03:35:22", "status": "active", "viewCount": 0, "postCount": 1, "commentCount": 1, "enabled": true }, { "id": 5, "name": "Announcements", "description": "Resources and staff communication.", "createdAt": "2023-03-04T03:35:22", "status": "active", "viewCount": 0, "postCount": 1, "commentCount": 1, "enabled": true }, { "id": 6, "name": "The Vault", "description": "Treasured memories of threads past.", "createdAt": "2023-03-04T03:35:22", "status": "active", "viewCount": 0, "postCount": 1, "commentCount": 1, "enabled": true } ]
The fields ending with 'Count' are all hardcoded numbers in db
there are no postsinside. therefore *ngFor="let post of category.posts;wont work
category.posts doesn't exist.
omg
Looks like I never added posts property to my category model
Oh wait I did
So why would posts not show up in the json if posts does exist in the category model?
Ah
I think i found it
if they don't show up, they probably don't exist.
try to double-check your code, debug it, add some console.log.
See if the posts really are added or not
a jsonignore annotation on the backend
mystery solved 🥳