binoculars
binoculars

Reputation: 2274

Variable inside function in angular 2

On every page of my app, I have a download button to download a certain, page specific file. Every page uses the same template.

To make sure I don't lose the progress of a download, I've made a global variable which holds the progress of the download:

this.global['setProgress_' + this.pageID](Math.round((progressEvent.loaded / progressEvent.total) * 100));

To show the progress on each page, I could use:

<progress-bar [progress]="global.getProgress_page1()"></progress-bar>

This works fine, but of course with this code you would see the same progress on every page, since I alway get the progress of page1.

How could I make this dynamic? I've tried:

<progress-bar [progress]="global.getProgress_{{pageID}}()"></progress-bar>

But this makes the app crash. What's the right syntax to do this?

Upvotes: 2

Views: 314

Answers (1)

D&#225;niel Kis
D&#225;niel Kis

Reputation: 2641

Try in this way:

<progress-bar [progress]="global['getProgress_'+pageID]()"></progress-bar>

Upvotes: 1

Related Questions