【问题标题】:How can i present items from an NgFor one step at a time on Angular我如何在 Angular 上一次展示 NgFor 中的项目
【发布时间】:2022-06-28 02:02:32
【问题描述】:

我有一个 ngfor,有 3 个项目,我想分步呈现它们,就像表单中的问题一样。例如,一旦回答了第一步,就只显示表单的第二个问题。

我也有一个 stackblitz 代码作为参考。 https://stackblitz.com/edit/angular-ivy-oauzgh?file=src%2Fapp%2Fapp.component.html

【问题讨论】:

    标签: angular typescript ngfor


    【解决方案1】:

    不确定 ngFor 是不是最好的方法,反正你可以添加

    <tr *ngFor="let hero of heroes; let i = index">
       <td *ngIf="i > currentIndex">{{hero.name}}</td>
       User do something and you increase the currentIndex
    </tr>
    

    在ts中你只需要声明currentIndex并在初始化时将其设置为0,并在Do something块中增加一个html调用的索引的方法

    【讨论】:

    猜你喜欢
    • 2020-09-25
    • 2023-02-12
    • 2020-09-18
    • 2020-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-11
    相关资源
    最近更新 更多