Skip to main content
added 4 characters in body
Source Link
Doomenik
  • 876
  • 1
  • 14
  • 30

The following scenario would be pretty easy in javascript but I got some problems getting it worked in Angular.

I got an Array like:

array a = ( "id" = 0, name = random(), column = 1, 2 or 3, blockrow= 1, 2 or 3)

With ngFor I try to create now a grid there all elements out of a get separated in colums and blocks in this column. So my current code (works but nasty).

<div *ngFor="let a of a">
  <template *ngIf="a[ngIf]="a.column=='1'">
    <div *ngFor="let b of a">
      <template *ngIf="b[ngIf]="b.blockrow=='1'">
        Block 1 in column 1{{b.name}}
      </template>
    </div>
    <div *ngFor="let b of a">
      <template *ngIf="b[ngIf]="b.blockrow=='2'">
        Block 2 in column 1{{b.name}}
      </template>
    </div>
    <div *ngFor="let b of a">
      <template *ngIf="b[ngIf]="b.blockrow=='3'">
        Block 3 in column 1{{b.name}}
      </template>
    </div>
  </template>
</div>

Something like this do I run for every column. Which means I loop trough the same array for 12 times. Is there any way to do it more beautifull ?

The following scenario would be pretty easy in javascript but I got some problems getting it worked in Angular.

I got an Array like:

array a = ( "id" = 0, name = random(), column = 1, 2 or 3, blockrow= 1, 2 or 3)

With ngFor I try to create now a grid there all elements out of a get separated in colums and blocks in this column. So my current code (works but nasty).

<div *ngFor="let a of a">
  <template *ngIf="a.column=='1'">
    <div *ngFor="let b of a">
      <template *ngIf="b.blockrow=='1'">
        Block 1 in column 1{{b.name}}
      </template>
    </div>
    <div *ngFor="let b of a">
      <template *ngIf="b.blockrow=='2'">
        Block 2 in column 1{{b.name}}
      </template>
    </div>
    <div *ngFor="let b of a">
      <template *ngIf="b.blockrow=='3'">
        Block 3 in column 1{{b.name}}
      </template>
    </div>
  </template>
</div>

Something like this do I run for every column. Which means I loop trough the same array for 12 times. Is there any way to do it more beautifull ?

The following scenario would be pretty easy in javascript but I got some problems getting it worked in Angular.

I got an Array like:

array a = ( "id" = 0, name = random(), column = 1, 2 or 3, blockrow= 1, 2 or 3)

With ngFor I try to create now a grid there all elements out of a get separated in colums and blocks in this column. So my current code (works but nasty).

<div *ngFor="let a of a">
  <template [ngIf]="a.column=='1'">
    <div *ngFor="let b of a">
      <template [ngIf]="b.blockrow=='1'">
        Block 1 in column 1{{b.name}}
      </template>
    </div>
    <div *ngFor="let b of a">
      <template [ngIf]="b.blockrow=='2'">
        Block 2 in column 1{{b.name}}
      </template>
    </div>
    <div *ngFor="let b of a">
      <template [ngIf]="b.blockrow=='3'">
        Block 3 in column 1{{b.name}}
      </template>
    </div>
  </template>
</div>

Something like this do I run for every column. Which means I loop trough the same array for 12 times. Is there any way to do it more beautifull ?

deleted 4 characters in body
Source Link
Doomenik
  • 876
  • 1
  • 14
  • 30

The following scenario would be pretty easy in javascript but I got some problems getting it worked in Angular.

I got an Array like:

array a = ( "id" = 0, name = random(), column = 1, 2 or 3, blockrow= 1, 2 or 3)

With ngFor I try to create now a grid there all elements out of a get separated in colums and blocks in this column. So my current code (works but nasty).

<div *ngFor="let a of a">
  <template [ngIf]="a*ngIf="a.column=='1'">
    <div *ngFor="let b of a">
      <template [ngIf]="b*ngIf="b.blockrow=='1'">
        Block 1 in column 1{{b.name}}
      </template>
    </div>
    <div *ngFor="let b of a">
      <template [ngIf]="b*ngIf="b.blockrow=='2'">
        Block 2 in column 1{{b.name}}
      </template>
    </div>
    <div *ngFor="let b of a">
      <template [ngIf]="b*ngIf="b.blockrow=='3'">
        Block 3 in column 1{{b.name}}
      </template>
    </div>
  </template>
</div>

Something like this do I run for every column. Which means I loop trough the same array for 12 times. Is there any way to do it more beautifull ?

The following scenario would be pretty easy in javascript but I got some problems getting it worked in Angular.

I got an Array like:

array a = ( "id" = 0, name = random(), column = 1, 2 or 3, blockrow= 1, 2 or 3)

With ngFor I try to create now a grid there all elements out of a get separated in colums and blocks in this column. So my current code (works but nasty).

<div *ngFor="let a of a">
  <template [ngIf]="a.column=='1'">
    <div *ngFor="let b of a">
      <template [ngIf]="b.blockrow=='1'">
        Block 1 in column 1{{b.name}}
      </template>
    </div>
    <div *ngFor="let b of a">
      <template [ngIf]="b.blockrow=='2'">
        Block 2 in column 1{{b.name}}
      </template>
    </div>
    <div *ngFor="let b of a">
      <template [ngIf]="b.blockrow=='3'">
        Block 3 in column 1{{b.name}}
      </template>
    </div>
  </template>
</div>

Something like this do I run for every column. Which means I loop trough the same array for 12 times. Is there any way to do it more beautifull ?

The following scenario would be pretty easy in javascript but I got some problems getting it worked in Angular.

I got an Array like:

array a = ( "id" = 0, name = random(), column = 1, 2 or 3, blockrow= 1, 2 or 3)

With ngFor I try to create now a grid there all elements out of a get separated in colums and blocks in this column. So my current code (works but nasty).

<div *ngFor="let a of a">
  <template *ngIf="a.column=='1'">
    <div *ngFor="let b of a">
      <template *ngIf="b.blockrow=='1'">
        Block 1 in column 1{{b.name}}
      </template>
    </div>
    <div *ngFor="let b of a">
      <template *ngIf="b.blockrow=='2'">
        Block 2 in column 1{{b.name}}
      </template>
    </div>
    <div *ngFor="let b of a">
      <template *ngIf="b.blockrow=='3'">
        Block 3 in column 1{{b.name}}
      </template>
    </div>
  </template>
</div>

Something like this do I run for every column. Which means I loop trough the same array for 12 times. Is there any way to do it more beautifull ?

removed tags
Link
Aravind
  • 41.7k
  • 16
  • 97
  • 111
edited tags
Link
David L
  • 34.1k
  • 8
  • 70
  • 98
Loading
Source Link
Doomenik
  • 876
  • 1
  • 14
  • 30
Loading