Currently, I am working on a basic app that retrieves posts from the server and displays them as cards on the screen. At this early stage, one of my main challenges is figuring out how to dynamically add ion-card elements with changing content and headers using TypeScript. The snippet below shows how I am trying to achieve this:
fillPost() {
for (let i: number = 0; i < 10; i++) {
this.postContainer += "<ion-card> "
+ "<ion-item> <h2 item-left> Name here </h2>"
+ "<p> Post Number : +"i+" </p> </ion-item> <ion-card-content>"
+ "<p> Post Body here </p> </ion-card-content>"
+"<ion-row > <ion-col > <button ion- button icon- left clear small> "
+ "<ion-icon name= \"thumbs-down\" > </ion-icon>"
+ "< div > Report < /div>"
+ "</button>"
+ "</ion-col>"
+ "<ion-col center text-center>"
+ "<ion-note>"
+ "1h ago"
+ "</ion-note>"
+ "</ion-col>"
+ "</ion-row>"
+ "</ion-card>";
}
}
When I run the code and call the fillPost() function in the HTML file like so:
<div [innerHTML]="postContainer">
</div>
I encounter issues where the output doesn't display as expected. Here's an example:https://i.sstatic.net/KiKrF.jpg. Any guidance or assistance in resolving this problem would be greatly appreciated. Thank you.