-1

In a razor page I can write:

 @for (int i = 1; i <= Model.TotPages; i++)
    {
        <div class="pagmenu">
            @if (i == Model.CurPage)
            {
                @Html.ActionLink(i.ToString(), "Index", "Home", new { curPage = i, catId = Model.CatId, discounted = Model.Discounted, search= Model.Search }, new { @class = "btn btn-primary" })
            }
            else
            {
                @Html.ActionLink(i.ToString(), "Index", "Home", new { curPage = i, catId = Model.CatId, discounted = Model.Discounted, search = Model.Search }, new { @class = "btn btn-default" })
            }
        </div>
    }

What is the equivalent in angular? *ngFor is the equivalent of foreach not of for, as I understand it.

1

1 Answer 1

1

if Angular you only can iterating over arrays, well you can create an array "on fly" using "repeat", see this SO

//in ts
n=10;

<div *ngFor="let a of ' '.repeat(n).split('');let i=index">
  {{i}}
</div>

or using a function to return an array

//in .ts
n=10;
getFoolArray(n)
{
    return new Array(n)
}

<div *ngFor="let a of getFoolArray(n);let i=index">
  {{i}}
</div>

Another option is create a directive repeat, see this SO answer

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

2 Comments

For reference, see this answer.
@ConnorsFan, really, I didn't saw your post, please, don't think it's stolen (else I usually redirect to the link)

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.