TypeError:无法读取未定义

时间:2018-04-22 23:24:16

标签: angular angular2-services

调用用java编写的服务的方法

 resendRealTime(envelopeIds: String[]): Observable<String> 
  {
    let headers = new HttpHeaders({ 'Content-Type': 'application/json',
        'Accept': 'application/json' });
     console.log(envelopeIds);
    let json = JSON.stringify({envelopeIds: envelopeIds});
    console.log(json);
     return this.http.post<String>(`${AppSettings.baseServiceUrl}/docusign/resendRealTime`, json, {headers: headers} )
    .catch((error: Response) => this.handleErrors(error));
}

调用上述方法的方法

 resendEnvelope() {
   let envelopeIdsArray = new Array<String>();
  console.log('Inside resend');
  this.envelopeIdsHolder.envelopeIds.forEach(function (item) {
      envelopeIdsArray.push(item);
  })

  this.backendService.resendRealTime(envelopeIdsArray).subscribe( result => console.log(`Service resend envelope returned '${result}'`));
}

Java服务

@RequestMapping(value = "/resendRealTime", method = {RequestMethod.POST})
public ResponseEntity<?> resendRealTime( @RequestBody EnvelopeIds envelopeIds) {
    log.info("envleopeIds : " + envelopeIds);
    System.out.println("inside resendrealtime");
    SwpDocuSignBulkLoader.resendRealTime(envelopeIds);

    return  new ResponseEntity<String>("ok", HttpStatus.OK);
}

我在这里使用角度中的HTTPCLIENTMODULE来进行调用,但是这里它正在撤销“TypeError:无法读取未定义的属性'subscribe'”。它返回ResponseEntity

的java端没有问题

1 个答案:

答案 0 :(得分:1)

您可以查看Observables in angular

const observ = this.http.post(...)
const handler = ovserv.share() // in case you want to handle it by yourself
handler.subscribe((results) => {}, (err) => {}, (complete) => {})
return handler

发生的事情是Observable.catch返回null,之后你试图&#34;订阅&#34;到一个未定义的对象。