我在一个页面上有多个下载按钮,每个下载都有一个进度条:
<progress-bar *ngIf="progressbar" [progress]="loadProgress_id1"></progress-bar>
<progress-bar *ngIf="progressbar" [progress]="loadProgress_id2"></progress-bar>
...
我有一个设置进度的函数:
setpercentage(perc,id) {
this.loadProgress_+id = Math.round(perc); // --> how could I do this?
this.ref.detectChanges();
}
我所尝试的(上述)不起作用。我怎样才能做到这一点?或者我应该使用不同的方法?
最佳答案
试试这个
setpercentage(perc,id) {
this['loadProgress_' + id] = ....
}
或
setpercentage(perc,id) {
const prop = 'loadProgress_' + id;
this[prop] = ...
}
关于javascript - angular2/javascript 中的动态变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43558727/