Angular 2 - ngFor display last 3 items in array

前端 未结 4 628
情书的邮戳
情书的邮戳 2021-02-06 15:44

got an array with many projects and i want to display the last 3 projects.

got in my html

          
  • 4条回答
    •  借酒劲吻你
      2021-02-06 16:36

      Gunter's answer above didn't work in my case. I was able to accomplish the same thing but slightly different:

      
          
    • {{ project.name }}

      {{ project.meta_desciption }}

    • If the index of the loop is greater then the length of the array minus 4. So if the length is less then 3 it prints all, if it is 3 or greater it just prints the last 3 in whatever order they come in.

    提交回复
    热议问题