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

5
  • you want to use *ngFor twice on tr ? Commented May 28, 2016 at 5:03
  • @PardeepJain yes and no) I need to insert two tr with same data but different structure. Commented May 28, 2016 at 5:05
  • Using bootstrap grid system instead of table can do the trick Commented May 28, 2016 at 5:08
  • @Illorian check my answer please Commented May 28, 2016 at 5:18
  • @ArunGhosh Unfortunately I must use table Commented May 28, 2016 at 5:36

2 Answers 2

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

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

1 Comment

Thanks. I really forgot about templates
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.

2 Comments

Is think it's not valid layout
@Illorian its valid but this does't make sense to repeat tbody may cause some design issue later so better to use template that we already have.

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.