【问题标题】:Angular collaps button in ngforngfor 中的角度折叠按钮
【发布时间】:2021-01-07 12:26:34
【问题描述】:

我在 Angular 的表格中使用 Bootstrap 的折叠按钮,但是,当我单击第一个按钮时,第二个按钮也会随之显示。我试过这个名字,但没有用。我是初学者。

<tr *ngFor="let table of tables$ |
    async ; let i= index"
    class="hover-highlight">
    <td>
        <p>
            <button class="btn btn-primary"
                name="A"
                type="button"
                data-toggle="collapse"
                data-target="#collapseExample"
                aria-expanded="false"
                aria-controls="collapseExample">
                    Button with data-target
            </button>
        </p>
        <div class="collapse"
            id="collapseExample">
                <div class="card card-body">
                    <ngb-highlight
                        [result]="table.numsuivie"
                        [term]="service.searchTerm">
                    </ngb-highlight>
                </div>
        </div>
    </td>

【问题讨论】:

    标签: angular bootstrap-4 datatable ngfor collapse


    【解决方案1】:

    试试这个:

     <button class="btn btn-primary"
     type="button"
     data-toggle="collapse"
     aria-expanded="false"
     [attr.data-target]="'#collapseExample'+table.id"
     [attr.aria-controls]="'collapseExample'+ table.id">
    

    【讨论】:

      【解决方案2】:

      这是因为您为两个按钮提供了相同的 ID。 尝试为 data-target="#collapseExample" 中的每个按钮提供唯一的 id,并将相同的 id 提供给 div 标签中的折叠属性 id="collapseExample" 下方。

      【讨论】:

        猜你喜欢
        • 2016-03-24
        • 2016-06-25
        • 2019-03-21
        • 1970-01-01
        • 2018-11-16
        • 1970-01-01
        • 2018-12-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多