После попытки предложенного подхода у меня все еще были проблемы с макетом.Спасибо за предложение, хотя!Это было информативно, так как заставило меня посмотреть, какие существуют варианты сетки CSS.
В конце концов, потому что мой контент имеет неизвестную переменную высоту, и он должен быть отзывчивым (3 столбца, 2 столбца, 1 столбец),Я решил сделать регулярный * ngFor над моим списком, после того как он был переиндексирован в зависимости от размера окна.Теперь каждая отдельная группа остается в цикле.
------- parent component --------
// when screen is resized, control how the categoryArray is sorted (1, 2, 3 columns)
@HostListener('window:resize', ['$event'])
onresize() {
this.changeCategoryArray(window.innerWidth);
}
changeCategoryArray(innerWidth) {
let arrayToUse = [];
if (innerWidth >= 992) {
if (this.currentNumberOfColumns !== 3) {
this.currentNumberOfColumns = 3;
arrayToUse = this.threeColArray;
}
} else if (innerWidth < 992 && innerWidth >= 576) {
if (this.currentNumberOfColumns !== 2) {
this.currentNumberOfColumns = 2;
arrayToUse = this.twoColArray;
}
} else if (innerWidth < 575) {
if (this.currentNumberOfColumns !== 1) {
this.currentNumberOfColumns = 1;
arrayToUse = this.oneColArray;
}
}
// only change it if it is not already set to the this number of columns
if (arrayToUse.length) {
for (let i = 0; i < this.categories.length; i++) {
this.newCategoryArray[arrayToUse[i]] = this.categories[i];
}
}
}
------------html----------
<div class="modal-body">
<div class="row m-4">
<div class="col-12 col-sm-6 col-lg-4" *ngFor="let item of newCategoryArray">
<ballot-category [categoryItem]="item"></ballot-category>
</div>
</div>
</div> <!-- end modal body -->
-----<ballet-category>------
<div class="pl-4 pr-4">
<div class="justify-content-sm-start justify-content-center text-sm-left text-center">
<span class="cat-title" [ngClass]="{'title-notPicked': !categoryItem.iPicked}">{{categoryItem.name}}</span>
<span class="cat-subtitle" *ngIf="categoryItem.subtitle" [ngClass]="{'title-notPicked': !categoryItem.iPicked}"> {{categoryItem.subtitle}}</span>
</div>
<div class="justify-content-sm-start justify-content-center text-sm-left text-center nom-name" *ngIf="categoryItem.iPicked">
<span>{{categoryItem.nomPicked}}</span>
</div>
<div class="justify-content-sm-start justify-content-center text-sm-left text-center nom-name-notPicked" *ngIf="!categoryItem.iPicked">
<span>/// Not chosen yet ///</span>
</div>
<hr />
</div>