【发布时间】:2016-08-08 22:29:16
【问题描述】:
我有一个简单的组件,它只呈现一个进度条。
它初始化很好,进度也很好地传递给它,但是模板没有用新值更新。
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;
}
}
~
其他地方
ngOnInit() {
this.httpFileService.progress$.subscribe((progress: number) => this.onProgress(progress));
}
onProgress(progress: number) {
this.progressBar.onProgress(progress*100);
}
我觉得我错过了一些非常有用的东西。
【问题讨论】:
-
如果您更新您的问题以向我展示如何调用
onProgress,我可能会让我的回答对您更有帮助 - 我怀疑这里使用了更深层次的反模式。 -
添加了 onProgress 部分。它是通过我订阅的 xhr onprogress 检索到的。
-
我是对的 :-) 请稍等,我会更新
标签: data-binding angular components