2

In Angular 5, *ngFor generate <div> elements in a column direction instead of row direction:

html:

    <div class="charts"  *ngFor="let chart of chartEntities$ | async; let i = index; trackBy: trackByFn"
          style="padding-top: 0.5em">
          <div class="item">
            <span style="background-color: rgb(127, 140, 255); height:120px;"> number {{i}}
            </span>
          </div>
    </div>

css:

    .charts{
      display: flex;
     flex-direction: row;
    }

    .item{
      display: flex;
      flex: 1
    }

How can I change it to all elements be in the same row?

Thanks

German Quinteros
  • 1,773
  • 8
  • 29
larry ckey
  • 131
  • 1
  • 13

2 Answers2

1

You need to add the *ngFor to your item, not the charts:

<div class="charts" style="padding-top: 0.5em">
  <div class="item" *ngFor="let chart of chartEntities$ | async; let i = index; trackBy: trackByFn">
    <span style="background-color: rgb(127, 140, 255); height:120px;">
      number {{i}}
    </span>
  </div>
</div>

on a side note, don't use inline styling like that. Those need to be moved to a component css file

Poul Kruijt
  • 64,681
  • 11
  • 135
  • 134
1

You should rearrange as

<div class="charts" style="padding-top: 0.5em">
      <div class="item" *ngFor="let chart of chartEntities$ | async; let i = index; trackBy: trackByFn">
        <span style="background-color: rgb(127, 140, 255); height:120px;"> number {{i}}
        </span>
      </div>
</div>

The display: flex; flex-direction: row; should be on the parent div

Shashank Vivek
  • 15,676
  • 8
  • 57
  • 96