2

I have a simple loop like this:

<div *ngFor="let treatment of data.treatments; let order = index">
    {{treatment.order}}
    <input type="text" [(ngModel)]="treatment.name.dutch" >
</div>

Now I would like to set treatment.order = order in my template code. So that the list would always be

1...
2...
3...

But also that the variable treatment.order would then have the corresponding order in the list. I can't seem to find a way to do this

1
  • Create a simple pipe and add a new property at each treatment. Commented Nov 28, 2017 at 16:54

1 Answer 1

1

create a sort pipe for sorting the array

More about pipes

stackoverflow question about sorting pipe

Example:

<div *ngFor="let treatment of data.treatments | sortOrder; let order = index">
    {{treatment.order}}
    <input type="text" [(ngModel)]="treatment.name.dutch" >
</div>
Sign up to request clarification or add additional context in comments.

Comments

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.