angular - Nativescript-Angular 在http服务调用后, View 未更新(Angular 5)

标签 angular nativescript angular2-nativescript

Nativescript-Angular 在 http 服务调用后, View 未更新(Angular 5)。

找到下面的代码,我在其中编写了 http 服务调用,然后将响应分配给未在 View 页面中更新的 View 。如果我执行任何其他事件(例如鼠标悬停在文本框上), View 就会更新。 componet.ts 文件

this.orderService.getProductBySKU('DR1056.01534XXL')
    .subscribe(resProduct => {
        this.ngZone.run(() => {
            this.processing = false;                
         });
    }

服务文件

getProductBySKU(sku) {
    const authToken = localStorage.getItem('currentUserToken');
    return this.http.get(this.config.apiUrl + 'get-product-by-sku?sku=' + sku, this.config.basicAuth())
 .map(response => response);

}

注意:默认情况下,this.processing 在显示在 View 中的构造函数中指定为 True,在服务调用后 this.processing 被指定为 False,但仅显示 True。如果我单击任何文本框或单击按钮,this.processing 在 View 中将更改为 False。

最佳答案

首先,我建议使用 HttpClient 参数选项来避免潜在的 URL 转义问题:

this.http.get(this.config.apiUrl + 'get-product-by-sku', {...this.config.basicAuth(), params: { sku: sku }})

```

至于处理,请尝试强制进行更改检测:

constructor(private ref: ChangeDetectorRef) {}
(...)
this.orderService.getProductBySKU('DR1056.01534XXL')
    .subscribe(resProduct => {
        this.ngZone.run(() => {
            this.processing = false;                
            this.ref.detectChanges();
         });
    }

如果这不起作用,请提供您的模板片段。

关于angular - Nativescript-Angular 在http服务调用后, View 未更新(Angular 5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51370536/

相关文章:

angular - Bootstrap 4 导航栏事件背景颜色

angular - Chunk 不包含延迟加载的组件

android - tns 调试期间没有请求

javascript - Nativescript Angular : Can't read object from inside a function (this. 未定义?)

css - 在按钮内垂直堆叠跨度

javascript - 在 Angular 应用程序中对 Observable 的 POST 请求使用 switchMap

angular - IE 11 中的 Flexbox 重叠 flex 元素

android - 如何使地理定位后台服务在我的 NativeScript-Angular 应用程序中工作?

nativescript - nativescript 搭档停产了吗?

android - 应用程序如何在 Nativescript 中检测到它将被卸载?