angular2: 'show more' in nested ngFor's

一笑奈何 提交于 2019-12-11 13:26:50

问题


I'm trying to implement something similar to this solution in angular2. I know I can use the slice pipe to limit the number of iterations (similar to limitTo). The thing is, there's no ng-init directive on angular2, and local variables doesn't seem to work in this scenario, and I can't use a variable in the component's level since it should be local to each sub entity (as seen in the example below).

 <template ngFor #record [ngForOf]="records" #i="index">
  <template #showMoreLocal="2" ngFor #object [ngForOf]="record.objects | slice:0:showMoreLocal" #j="index">
    ....some htmls....
    <button *ngIf="showMoreLocal < record.objects.length" (click)="showMoreLocal = showMoreLocal + 10">..</button>
  </template>
</template>

来源:https://stackoverflow.com/questions/36673835/angular2-show-more-in-nested-ngfors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!