任何想法如何將數據綁定到Angular2的進度條? {{}}不適用於現有的屬性,如aria-valuenow或progress tag的值。以下是引導程序。綁定進度條
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="70"
aria-valuemin="0" aria-valuemax="100" style="width:70%">
<span class="sr-only">70% Complete</span>
</div>
</div>
更新更多的細節
update.service.ts:這是創建obseverable,
public _progress$: Observable<number>;
private _progress: number = 0;
private _progressObserver: Observer<number>;
constructor(private _http:Http, private _configurationService: ConfigurationService,private _authenservice:AuthenticationService) {
this._progress$ = new Observable(observer => {
this._progressObserver = observer
});
}
....
this._progressObserver.next(this._progress); // this is to push in the progress number from xhr.upload.onprogress
home.component.ts:其中顯示進度條的部件,
private _uploadProgressStatus:Observable<number>;// as "asyn" only takes in the promise of observable, I plan to feed _uploadProgressStatus in
constructor(private _videoManagementService:VideoManagementService,
private _uploadService:UploadService) {
console.info('HomeComponent Mounted Successfully');
this._uploadProgressStatus = this._uploadService._progress$;
this._uploadProgressStatus.subscribe(
data => {
console.log('progress = '+data/100);
}); //if subscribe to this._uploadProgressStatus, no values are received...
this._uploadService._progress$.subscribe(
data => {
console.log('progress = '+data/100);
});
} // if subscribe to this._uploadService._progress$ ,numbers are received.
home.component.html
<h4>Uploading...{{ _uploadProgressStatus | async | percent}}</h4>
<div class="progress">
<div class="progress-bar" role="progressbar" [style.width]="_uploadProgressStatus | async | percent" aria-valuemin="0" aria-valuemax="100">
<h4>{{ _uploadProgressStatus | async | percent}} </h4>
</div>
</div>
這是行不通的。所以問題是如何在home.component.ts中創建觀察值以接收數字?
在HTML更新_uploadProgressStatus到_uploadService._progress $也沒有工作
if Start ....................................... function myStartFunction() myVar = setInterval(myTimer,200); } –
謝謝。是的,設置時間間隔肯定可以工作。如果(a> = 99){myStopFunction(); ....和你的函數....我更關注在Angular2 – Hammer
中是否有任何方法。} –