首页 > 解决方案 > 如何使用 *ngFor 外部的索引访问数据

问题描述

我想访问 *ngFor 之外的数据

    <mat-carousel timings="250ms ease-in" [autoplay]="false" interval="5000" color="accent" maxWidth="93%"
                proportion="80" slides="3" slideHeight="100%" [loop]="false" [hideArrows]="false" [hideIndicators]="true"
                [useKeyboard]="false" [useMouseWheel]="false" orientation="ltr" maintainAspectRatio="false">
    <mat-carousel-slide #matCarouselSlide *ngFor="let event of myvideo; let i = index"
                  overlayColor="#00000040" [hideOverlay]="true">
                          <video *ngIf="event?.Video" controls style="width: 100%;">
                          <source src="{{event?.Video}}" type="video/mp4">
                          Browser not supported
                        </video>
    </mat-carousel-slide>

***I want to get in this part {{event?.title}}*** 
    </mat-carousel>

请问你能和我分享任何想法吗?这是可能的?

标签: angulartypescriptcarouselngfor

解决方案


@Site,我认为您正在寻找ng-container - 它不会创建额外的标签-

<ng-container *ngFor="let event of myvideo; let i = index">
  <mat-carousel-slide #matCarouselSlide >...
  </mat-carousel-slide>
  {{event?.title}}
</mat-carousel>

但我真的认为“标题”应该在 mat-carousel-slide 里面


推荐阅读