【问题标题】:ngFor index plus 1 or incresed count by onengFor 索引加 1 或计数加 1
【发布时间】:2016-09-01 15:39:57
【问题描述】:

如何在角度 2 中获取索引但增加 1:

<li *ngFor="let mPrepTasks of project.upcomingMeetingsPrepTask; let i= index; let count = i+ 1;">
   <p>Index {{count}}</p>
</li>

【问题讨论】:

    标签: angular angular2-template angular2-directives


    【解决方案1】:

    为什么不这样做:

    <li *ngFor="let mPrepTasks of project.upcomingMeetingsPrepTask; let i= index;">
       <p>Index {{i + 1}}</p>
    </li>
    

    【讨论】:

      【解决方案2】:

      您不能创建任意模板变量。在*ngFor 中,您只能声明由*ngFor 指令提供的变量。

      要么按照@FilipLauc 所说的去做,要么在组件类中进行计算。

      【讨论】:

        猜你喜欢
        • 2016-12-27
        • 1970-01-01
        • 2021-10-25
        • 2022-07-12
        • 1970-01-01
        • 2012-05-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多