I have a view with the following snippet:
<div *ngIf="step" [sortablejs]="orderedId" [sortablejsOptions]="optionsSortable">
<div *ngFor="let item of step.items" class="item">
<div class="position">{{item.position}}</div>
<div class="text">{{item.text}}</div>
</div>
</div>
In controller, I have the following snippet:
export class AppComponent implements AfterViewInit {
step: StepInterface;
stepId: number;
orderedId: Array<number>;
constructor(private api: ApiService) {
this.stepId = 1 //Debug
this.optionsSortable = {
onUpdate: (event: any) => {
this.api.organize(this.stepId, this.orderedId).subscribe((response) => {
this.step = response;
this.buildArray();
});
}
};
}
ngAfterViewInit() {
this.api.get(this.stepId).subscribe((data) => {
this.step = data;
this.buildArray();
});
}
private buildArray() {
this.orderedId = [];
for (const item of this.step.items) {
this.orderedId.push(item.id);
console.log(clue.id);
}
}
}
In fact, I have sortable div and when user modify the position, data is updated with backend. Problem is when the position is updated, so object "step" modified, {{item.position}} is not refreshed in view. How can I update the position in view after position modification?
Thank you