【问题标题】:How to display length of Array in for loop?如何在for循环中显示数组的长度?
【发布时间】:2019-01-26 12:46:05
【问题描述】:

我想在我的 html 代码中显示数组的长度。数组列表包含另一个数组列表,所以我必须在外部数组迭代时显示内部数组列表的长度

这是我的html代码

<div class="col-xs-12 col-sm-4 col-md-3 col-lg-2 cols" *ngFor="let productMapper of printProducts">
            <md-card>
                <div (click)=" gotoLink(productMapper)">
                    <div class="text-center img-wrapper">
                        <img [src]="productMapper.product.imagePath" class="img-responsive" />
                    </div>
                    <div class="divider"></div>
                    <div class="text-center divider_text" title="{{productMapper.product.productName}}">
                        <span> {{productMapper.product.productName}} </span>

                    </div>
                </div>
                <div class="starRatingBlock text-center" (click)="viewComments($event);">
                    <span class="commentsBlock">
                        <i class="fa fa-commenting-o" aria-hidden="true"> {{productMapper.surveyData.length}}</i>
                    </span>
               </div>
         <md-card>
  </div>

我试过了,但没用:{{productMapper.surveyData.length}}

【问题讨论】:

  • 它应该可以工作。你确定productMapper.surveyData 是一个数组吗?
  • but not working 是什么意思?
  • surveyData 应该是内部数组。如果是这样,它应该可以工作。请添加更多代码并提供您的数据示例
  • 您是否收到错误消息?

标签: angular typescript


【解决方案1】:

aria-hidden 属性设置为false

<i class="fa fa-commenting-o" aria-hidden="false"> {{productMapper.surveyData.length}}</i>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-13
  • 1970-01-01
  • 2021-12-27
  • 2015-09-30
相关资源
最近更新 更多