我有一个简单的组件,只是呈现进度条.
它初始化很好,进度很好,但模板没有使用新值更新.
import {Component} from 'angular2/core';
@Component({
selector : 'progress-bar',
template : `
<div class="progress-container">
<div>{{currentProgress}}</div>
<div [style.width.%]="currentProgress" class="progress"></div>
</div>
`,
styles: [
'.progress-container {width: 100%; height: 5px}',
'.progress {background-color: #8BC34A; height:5px}'
]
})
export class ProgressBar {
currentProgress: number;
constructor() {
this.currentProgress = 0;
}
onProgress(progress: number) {
console.log(progress) //consoles correct percentages
this.currentProgress = progress;
}
reset() {
console.log(this.currentProgress) //is 100
this.currentProgress = 0;
}
}
~
Run Code Online (Sandbox Code Playgroud)
别处
ngOnInit() {
this.httpFileService.progress$.subscribe((progress: number) => this.onProgress(progress));
}
onProgress(progress: number) {
this.progressBar.onProgress(progress*100); …Run Code Online (Sandbox Code Playgroud)