0

I have a Component with table template.

This is part:

<tr *ngFor="let stat of statistic" class="stripped">
        <td>{{stat.date         | date:"shortDate"}}</td> 
        <td>{{stat.hits         | number }}</td>
        <td>{{stat.unique       | number }}</td>
        <td>{{stat.registrations| number }}</td>
        <td>{{stat.conversion   | number }}</td>
        <td>{{stat.deposit      | number }}</td>
        <td>{{stat.ftd          | number }}</td>
        <td class="bold">{{stat. deals | number }}</td>
        <td class="bold colored">{{stat.profit| currency:'USD':true:'1.2' }}</td>
</tr>

But instead of tr I need to insert two. If I try to use it as another component, a table breaks.

Is there a tricky way to insert another tr after each tr in cycle? Or maybe has a way of exchange Component selector on his template

Illorian
  • 1,222
  • 2
  • 13
  • 38

2 Answers2

1

as you said in comment you want to use same data but want two tr so you can try this one :-

<template ngFor let-stat [ngForOf]='statistic'>
    <tr class="stripped">
        <td>{{stat.date | date:"shortDate"}}</td>
        <td>{{stat.hits | number }}</td>
        <td>{{stat.unique | number }}</td>
        <td>{{stat.registrations| number }}</td>
        <td>{{stat.conversion | number }}</td>
        <td>{{stat.deposit | number }}</td>
        <td>{{stat.ftd | number }}</td>
        <td class="bold">{{stat. deals | number }}</td>
        <td class="bold colored">{{stat.profit| currency:'USD':true:'1.2' }}</td>
    </tr>
    <tr class="stripped">
        <td>{{stat.date | date:"shortDate"}}</td>
        <td>{{stat.hits | number }}</td>
        <td>{{stat.unique | number }}</td>
        <td>{{stat.registrations| number }}</td>
        <td>{{stat.conversion | number }}</td>
        <td>{{stat.deposit | number }}</td>
        <td>{{stat.ftd | number }}</td>
        <td class="bold">{{stat. deals | number }}</td>
        <td class="bold colored">{{stat.profit| currency:'USD':true:'1.2' }}</td>
    </tr>
</template>

see here for more tricky way of using *ngFor in angular2 https://angular.io/docs/ts/latest/api/common/NgFor-directive.html

Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
0

You can use tbody

<tbody *ngFor="let stat of statistic" class="stripped">
   <tr></tr>
   <tr></tr>
</tbody>

Form this answer you can have multiple tbody in a table.

Using bootstrap grid system instead of table can do the trick.

Community
  • 1
  • 1
Arun Ghosh
  • 7,634
  • 1
  • 26
  • 38