简体   繁体   English

nativescript-background-http 分离视图

[英]nativescript-background-http detaches view

ai am creating application with naticescript and angular.我正在使用 naticescript 和 angular 创建应用程序。 I have implemented progress indicator with messages.我已经用消息实现了进度指示器。 While testing from angular components everything works fine however when i start using real nativescript-background-http progress indicator view seems gets detached because it stops updating untill either i call detectChanges in view or post messages from upload functionallity with ngZone.run.在从 angular 组件进行测试时,一切正常,但是当我开始使用真正的 nativescript-background-http 进度指示器时,视图似乎已分离,因为它停止更新,直到我在视图中调用 detectChanges 或使用 ngZone.run 从上传功能发布消息。 This all would be understandable but later in sequence i have other messages posted (rxjs) to same progress indicator from normal component and i see them comming in console but display value is not updated.这一切都是可以理解的,但稍后我将其他消息(rxjs)从普通组件发布到相同的进度指示器,我看到它们在控制台中出现,但显示值没有更新。

Why progress indicator, which lives in separate component, gets detached?为什么存在于单独组件中的进度指示器会分离?

I was able to solve this issue.我能够解决这个问题。 I was completing observable outside Angular Zone.我在 Angular 区域之外完成了 observable。

task.on('progress', (e) => {
                if (e.currentBytes) {
                    // console.log('progress ->', e.currentBytes);
                    this.ngZone.run(() => {
                        this.componentService.loadingIndicator.showProgress({ maxValue: e.totalBytes, value: e.currentBytes });
                    });
                }
            });
            task.on('error', (e) => {
                this.ngZone.run(() => {
                    observer.error(e.error);
                    observer.complete();
                });
            });
            task.on('complete', (e: any) => {
                this.ngZone.run(() => {
                    observer.next(JSON.parse(e.response.getBodyAsString()));
                    observer.complete();
                });
                console.log('complete upload');
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM