我尝试使用* Ngif用于除了最后2个之外的所有列,我已经尝试了几个小时,但到目前为止没有工作
mes变量具有当前月份的数量。
listaMonthsNames
与当前月份具有相同数量的元素
check变量是布尔值设置为false
<thead>
<tr>
<th></th>
<ng-container *ngFor="let month of listaMonthsNames let idx=index">
<th class="col-{{idx}}" *ngIf="check">{{month}}</th>
</ng-container>
</tr>
</thead>
当我点击它时,我也有一个复选框显示数组listaMonthsNames
的所有月份,如果我再次点击它会隐藏所有月份,但我希望它可以留下最后2个月可见
答案 0 :(得分:1)
如果您尝试应用ngFor来排除列,则可以使用切片管道:
<....*ngFor="let month of listaMonthsNames | slice: mySlicer"...>
其中mySlicer
可以包含0
的值 - 包括所有 - 至listaMonthsNames.length
- 排除N
区间内的所有号码和[0;listaMonthsNames.length]
个号码以排除N个列,例如:2
- 排除前两列,如此demo example
答案 1 :(得分:0)
试试这个,这只会显示listaMonthsNames
<thead>
<tr>
<th></th>
<ng-container *ngFor="let month of listaMonthsNames let idx=index">
<th class="col-{{idx}}" *ngIf="(idx == listaMonthsNames.length || idx == (listaMonthsNames.length-1))">{{month}}</th>
</ng-container>
</tr>
</thead>