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,870
  • 9
  • 33
larry ckey
  • 141
  • 2
  • 14

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
  • 69,713
  • 12
  • 145
  • 149
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
  • 16,888
  • 8
  • 62
  • 104