2

I have multiple download buttons on a page, with a progress bar for each download:

<progress-bar *ngIf="progressbar" [progress]="loadProgress_id1"></progress-bar>
<progress-bar *ngIf="progressbar" [progress]="loadProgress_id2"></progress-bar>

...

I have a function that sets the progress:

setpercentage(perc,id) {
    this.loadProgress_+id = Math.round(perc); // --> how could I do this?
    this.ref.detectChanges();
}

What I've tried (the above) doesn't work. How could I achieve this? Or should I use a different approach?

1
  • 1
    this['loadProgress' + id] = Commented Apr 22, 2017 at 11:43

2 Answers 2

1

try this

setpercentage(perc,id) {
    this['loadProgress_' + id] = ....
}

or

setpercentage(perc,id) {
    const prop = 'loadProgress_' + id;
    this[prop] = ...
}
Sign up to request clarification or add additional context in comments.

Comments

1

Is there any reason an array wouldn't work for this?

// Html

<progress-bar 
  *ngFor="let progress of progressBars" 
  [progress]="progress"
></progress-bar>

// Ts

progressBars: number[] = [0,0];

setpercentage(perc,id) {
  this.progressBars[id] = Math.round(perc);
  this.ref.detectChanges();
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.