I have a problem when I use *ngFor
and *ngIf
on the same element.
<div
*ngFor="let recipeStep of RecipeSteps; let i = index"
*ngIf="position === i">
{{ recipeStep }}
</div>
<button ion-button small (click)="previous()">Previous</button>
<button ion-button small (click)="next()">Next</button>
I know the easy solution is to move the
*ngIf
on a new element. For Example:
<ng-container *ngIf="position === i">
<div *ngFor="let recipeStep of RecipeSteps; let i = index">
{{ recipeStep }}
</div>
<ng-container>
but when I use this solution I can't use i
variable. and this solution hide all element on <ng-container>
So, this buttons is not useful now
<button ion-button small (click)="previous()">Previous</button>
<button ion-button small (click)="next()">Next</button>
this typescript fill
position: number;
ionViewDidLoad() {
this.position = 1;
}
next() {
this.position = this.position + 1;
}
previous() {
this.position = this.position - 1;
}
My question is Are there different way use *ngFor
and *ngIf
on the same element.
If there are no way are there different way to be this buttons useful