0

I would like to display the records in a matrix way so that my actual output will look as below.

Lorium 001
Lorium 002
Lorium 003
----------
Ipsum 001
Ipsum 002
Ipsum 003 

Currently it is generating in a one line as below.

Lorium
001
002
003
Ipsum
001
002
003

Code snippet and also please review StackBlitz working demo

<div class="container">
    <div class="row" *ngFor="let element of data">
        <div class="col s4">
            <mat-form-field class="">
                <input matInput type="text" value={{element.value}} readonly>
        </mat-form-field>
        </div>
        <div class="sub-collection">
            <div class="col s4" *ngFor="let subElement of element.sizes">
                <mat-form-field class="">
                    <input matInput type="text" value={{subElement.subValue}} readonly>
        </mat-form-field>
            </div>
        </div>
    </div>
</div>

1 Answer 1

1

Try

<div class="container">
    <div class="row" *ngFor="let element of data; let first = first">
    <div *ngIf="!first">----------</div>
    <ng-container *ngFor="let subElement of element.sizes">
      <div class="col s4">
        <mat-form-field class="">
          <input matInput type="text" value={{element.value}} readonly>
        </mat-form-field>
        <mat-form-field class="">
          <input matInput type="text" value={{subElement.subValue}} readonly>
        </mat-form-field>
      </div>
    </ng-container>
    </div>
</div>

See modified stackblitz: https://stackblitz.com/edit/angular-dxyzqb?file=src/app/app.component.html

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much for your valuable response !!! It works as what I am looking. Btw did not get that concept of let first = first ? Is it a concept of Indexing ?
first is a local variable of the ngForOf directive. You can't use it unless you assign it. You could also write e.g. let isFirst = first to avoid naming confusion. Read further angular.io/api/common/NgForOf#local-variables

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.