Issue
I'm learning to use Angular and I have a problem about how to show data in column.
In my app.components.ts I have:
<div class="cardComp" *ngFor="let person of people">
<app-card-person [person]="person"></app-card-person>
</div>
// people is an array of objects
In my card-person.component.ts
<div class="card" style="width: 18rem;">
<!-- <img src="..." class="card-img-top" alt="..."> -->
<div class="card-body">
<h5 class="card-title">{{person?.name}} {{person?.surname}}</h5>
<p class="card-text">{{person?.description}}</p>
<!-- <a href="#" class="btn btn-primary">Go somewhere</a> -->
</div>
</div>
In this way I obtain a list of card but they are 1 for row:
CARD1
CARD2
CARD3
.....
What I would to obtain is:
CARD1 CARD2
CARD3 CARD4
..... .....
Solution
Solution 1: Work with flexbox
.container {
display: flex;
flex-wrap: wrap;
}
.item {
flex: 50%;
}
<div class="container">
<div class="cardComp item" *ngFor="let person of people">
<app-card-person [person]="person"></app-card-person>
</div>
</div>
Result
Sample Solution 1 on StackBlitz
Recommended to read this Flexbox article.
Solution 2: Work with Bootstrap
Pre-requisites: Import Bootstrap CSS file.
<div class="row">
<div class="cardComp col-6" *ngFor="let person of people">
<app-card-person [person]="person"></app-card-person>
</div>
</div>
Result
Sample Solution 2 on StackBlitz
Answered By - Yong Shun
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.