如何跟踪 angular 2 次服务呼叫的进度
how to track progress in angular 2 service call
我听说我们使用服务与数据库或其他数据存储库对话。当查询正在执行时,我希望能够在 UI 上放置一个进度条。
您如何跟踪完成百分比?
谢谢
您可以选择 模块。
否则,可以对 jQuery 中的 XHR progress
事件执行相同的操作:
import { Subject } from 'rxjs/Subject';
export class ProgressLoader {
percentage$: Subject<any>;
constructor() {
this.percentage$ = new Subject();
$.ajax({
type: 'GET',
url: 'http://google.com',
xhr: function() {
var xhr = new window.XMLHttpRequest(),
xhr.addEventListener("progress", (evt) => {
this.percentage$.next(parseInt(evt.loaded / evt.total * 100, false) + '%');
}, false);
return xhr;
}
});
}
}
我听说我们使用服务与数据库或其他数据存储库对话。当查询正在执行时,我希望能够在 UI 上放置一个进度条。
您如何跟踪完成百分比? 谢谢
您可以选择 模块。
否则,可以对 jQuery 中的 XHR progress
事件执行相同的操作:
import { Subject } from 'rxjs/Subject';
export class ProgressLoader {
percentage$: Subject<any>;
constructor() {
this.percentage$ = new Subject();
$.ajax({
type: 'GET',
url: 'http://google.com',
xhr: function() {
var xhr = new window.XMLHttpRequest(),
xhr.addEventListener("progress", (evt) => {
this.percentage$.next(parseInt(evt.loaded / evt.total * 100, false) + '%');
}, false);
return xhr;
}
});
}
}