Angular css类绑定

时间:2018-04-20 11:05:32

标签: css angular5

任何人都可以建议我如何整合这个我有8个css类,我希望它在第一个div中插入它们 ,这些是feature_destination1到featured_destination8

的类名
<div *ngFor="let destination of destinations;" class="box featured_destination1">
    <div class="img-wrapper">
      <img class="featured_img" src="https://d2aixmiphfue7s.cloudfront.net/fimages/{{destination.FeatureImage}}">
    </div>
    <div class="gradient">
      <div class="boxcontent">
        <div class="featuredtitle">Lorem ipsum dolor sit amet, consectetur nec risus adipiscing elit</div>
        <div class="featuredlocation">{{destination.TextLine1}} </div>
        <div class="featuredcountry">{{destination.LocationName}}Y</div>
      </div>
    </div>
  </div>

1 个答案:

答案 0 :(得分:0)

您可以将索引保存在每个循环的变量中,以便获得当前的循环索引。在此之后,您可以将值连接到类名。

试试这个:

<div *ngFor="let destination of destinations; let i = index;" class="box featured_destination{{i}}">

第一个循环的索引从0开始。因此,如果您希望类名在0的情况下以1开头,请尝试以下方法:

<div *ngFor="let destination of destinations; let i = index;" class="box featured_destination{{i + 1}}">

<div *ngFor="let destination of destinations; let i = index + 1;" class="box featured_destination{{i}}">