23

i want to create a ngFor Loop without a div tag.

Is this somehow possible?

My Problem is, that when i use a div *ngFor the slider is broken.

<ion-slides #secondSlider [options]="secondSlideOptions" (ionDidChange)="onSecondSlideChanged()">
    <!-- This div should not be there --> 
    <div *ngFor="let set of exercise.sets; let setNumber = index;">
        <ion-slide>
        ...
        </ion-slide>

        <ion-slide>
        ...
        </ion-slide>
    </div>
</ion-slides>

Is there another way to use ngFor without that div container?

Thanks a lot!

Fargho
  • 1,267
  • 4
  • 15
  • 30
  • You can use *ngFor anywhere, use it directly in the template if you need it there or do it in a span that probably it won't break you slider – nicowernli Nov 21 '16 at 12:47

2 Answers2

45

ng-container may be better.

See https://github.com/angular/angular/issues/11994

<ng-container *ngFor="let i of items" >
{{i.name}}
</ng-container>
Junichi Sakaeda
  • 553
  • 4
  • 4
3
<template ngFor let-set [ngForOf]="exercise.sets" let-setNumber="index">
// ...
</template>
rodrigocfd
  • 6,450
  • 6
  • 34
  • 68
  • @Fargho I'm glad it worked. Please consider [accepting the answer](http://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution. – rodrigocfd Nov 21 '16 at 11:27