我只想知道一件小事。我希望改進用于顯示隱藏td.
1例如,當我單擊按鈕時,會顯示隱藏的元素。

我的問題是,我想單擊以激活隱藏td,再單擊以停用隱藏td以顯示表格的每個元素。

代碼在Stackblitz 上
uj5u.com熱心網友回復:
希望我已經正確理解您的要求,在您的toggle()功能中替換
this.currentIndex = index;
和
if(index === this.currentIndex) {
this.currentIndex = null;
} else {
this.currentIndex = index;
}
在當前選定的 td 按鈕上呼叫該功能后,您必須重置當前索引。
uj5u.com熱心網友回復:
<tr *ngIf="currentIndex === i && show">
<td colspan="3"></td>
<td colspan="6">
<ng-container>
<table
class="table table-striped"
style="width:100%; text-align: center;"
>
<thead>
<tr style="color: red">
<th scope="col" style="width: 4%; ">Note 1</th>
<th scope="col" style="width: 4%; ">Note 2</th>
</tr>
<tr>
<td scope="col" style="">5</td>
<td scope="col" style="">8</td>
</tr>
</thead>
</table>
</ng-container>
</td>
<td colspan="3"></td>
</tr>
toggle(index) {
console.log(index);
this.currentIndex = index;
// CHANGE THE NAME OF THE BUTTON.
if (this.show) {
this.buttonName = 'Hide';
this.show = false;
} else {
this.buttonName = 'Show';
this.show = true;
}
}
你實際上并沒有切換 div
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/317153.html
上一篇:打字稿:從聯合型別中排除未定義
