什么可能导致 Nativescript angular2 中的承诺失败? [英] What could cause a promise to fail in Nativescript angular2?

查看:20
本文介绍了什么可能导致 Nativescript angular2 中的承诺失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从数据库中 Http GET,我可以访问该数据库并且可以在 Postman 中重现 GET 结果.

I am trying to Http GET from a database , where I do have access and can reproduce the GET result in Postman.

我在 angular2 {N} 中创建了一个服务,我在其中执行了这个 GET 但我得到了一个错误:

I have created a service in angular2 {N} where I execute this GET but I get an error of :

JS: EXCEPTION: Error: Uncaught (in promise): Response with status: 200  for URL: null

JS: STACKTRACE:
JS: Error: Uncaught (in promise): Response with status: 200  for URL: null
JS:     at resolvePromise (/data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:496:32)
JS:     at resolvePromise (/data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:481:18)
JS:     at /data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:529:18
JS:     at ZoneDelegate.invokeTask (/data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:314:38)
JS:     at Object.NgZoneImpl.inner.inner.fork.onInvokeTask (/data/data/org.nativescript.ndemo/files/app/tns_modules/@angular/core/src/zone/ng_zone_impl.js:37:41)
JS:     at ZoneDelegate.invokeTask (/data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:313:43)
JS:     at Zone.runTask (/data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:214:48)
JS:     at drainMicroTaskQueue (/data/data/org.nativescript.ndemo/files/app/tns_modules/zone.js/dist/zone-node.js:432:36)
JS: Unhandled Promise rejection: Response with status: 200  for URL: null ; Zone: angular ; Task: Promise.then ; Value: Response with status: 200  for URL: null
JS: Error: Uncaught

 (in promise): Response with status: 200  for URL: null

我的服务:

import { Headers, Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';
export function createNonJsonResponse(http: Http, fullUrl: string): Promise<string>{
    return http.get(fullUrl)
            .toPromise()
            .then(response => response.text())
            // .catch(this.handleError);
}

我已经记录了给定的 URL 和 Http,它们都很好.我不知道为什么会发生这种情况,谷歌也无法帮助我找到任何解决方案.

I have logged both the URL given in and the Http and they are fine. I have no idea why is this happening and google couldn't help me find any solutions whatsoever.

推荐答案

看来,至少对我来说,@angular/core Http 模块没有按预期工作.我切换到 nativescript 的 Http 服务(https://docs.nativescript.org/cookbook/http) 并设法毫无问题地完成了我需要的工作.

It seems, at least for me, @angular/core Http module is not working as intended. I switched to the nativescript's Http service (https://docs.nativescript.org/cookbook/http) and managed to accomplish what I needed without any problems.

这篇关于什么可能导致 Nativescript angular2 中的承诺失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆