JS:错误TypeError:无法读取未定义的属性“ Host”

时间:2019-07-17 09:55:07

标签: angular typescript http angular7 put

我正在尝试在NativeScript移动应用程序中进行放置调用。我正在使用Angular 7,但遇到一个奇怪的错误:

  

JS:错误类型错误:无法读取未定义的属性“主机”

我的 name.component.tns.ts 文件:

currentLocation: string = "Italy"; currentAdress: string = "Bla 23";

  constructor(
    private serviceManager: ServiceManager   ) {}

  controlAddressToLocation() {
    this.serviceManager.assignAddressToLocation(
      this.currentLocation,
      this.currentAddress
    );   }

我的 serviceManager.tns.ts 文件:

  assignAddressToLocation(
    currentLocation,
    currentAddress
  ): Observable<Location> {
    let headers = this.createRequestHeader();
    const body = JSON.stringify([currentAddress]);
    return this.httpClient.put<any>(
      "URL" +
        currentLocation +
        "/adress",
      body,
      { headers: headers }
    );
  }

  createRequestOptions() {
    let headers = new HttpHeaders({
      Accept: "application/json",
      "Content-Type": "application/json",
      "Accept-Encoding": "gzip, deflate, br",
      "Accept-Language": "en-US,en;q=0.9",
      "Cache-Control": "no-cache",
      Connection: "keep-alive"
    });
    return headers;
  }

0 个答案:

没有答案