当使用完全相同的Rest服务时,Angular2 web和Angular2 / Nativescript应用程序似乎具有不一致的行为

时间:2017-01-30 11:09:28

标签: rest angular nativescript angular2-nativescript

我忙于使用非常基本的Angular2 / Nativescript应用。我使用RestService与本地API通信,似乎有一些不一致的结果。 Web应用程序也使用此Rest Service,没有任何问题。当我调用ping(ip:string)函数来测试本地服务器的IP地址时,我得到一个错误,当我在console.log时它输出的错误是:

JS:TypeError:error.json()不是函数

知道这意味着什么吗?有没有办法调试/看看使用Nativescript发生了什么?
我能想到的移动应用和webb应用之间的唯一区别是每个都使用不同版本的Typescript,这可能与我的问题有关吗?

The ping function that doesn't work on the mobile app:

ping(ip: string) : Observable<any> {
      let tempUrl: string = "http://" + ip + "/BRMServices/WebEnquiry/ping";      
      return this.http.get(tempUrl)
      .map((res: Response) => res.json())
      .catch((error: any) => Observable.throw(error.json().error || 'server error'));
  }  


 The following function works perfectly on the mobile and web apps:

 getProduct(barcode: string): Observable<ProductModel> {          
      return this.http.get('http://10.60.160.34/BRMServices/WebEnquiry/' + "/POSEnquiry/" + barcode)
      .map((res: Response) => res.json())
      .catch((error: any) => Observable.throw(error.json().error || 'Server error'));
  }

  The Nativescript app uses Typescript V2.0.2,
  The webb app uses Typescript V~2.0.3

0 个答案:

没有答案