简体   繁体   English

在映射 https 响应时获取 [object Object]

[英]Getting [object Object] while mapping https response

I am getting an [object Object] while using Observable map in angular 10.在 angular 10 中使用 Observable map 时,我得到了一个 [object Object]。

Here is the response object from the API service.这是来自 API 服务的响应 object。

{
  "result": {
    "subject": {
      "name": "ROBERT JAZGARA",
      "nip": "7272445205",
      "statusVat": "Czynny",
      "regon": "472301670",
      "pesel": null,
      "krs": null,
      "residenceAddress": "ZAGŁOBY 21/10, 02-495 WARSZAWA",
      "workingAddress": null,
      "representatives": [],
      "authorizedClerks": [],
      "partners": [],
      "registrationLegalDate": "2002-05-21",
      "registrationDenialBasis": null,
      "registrationDenialDate": null,
      "restorationBasis": null,
      "restorationDate": null,
      "removalBasis": null,
      "removalDate": null,
      "accountNumbers": [
        "95213000042001029002150001",
        "78105019241000009719369622"
      ],
      "hasVirtualAccounts": false
    },
    "requestId": "mbn71-88a34h6",
    "requestDateTime": "27-07-2020 23:52:30"
  }
}

Here is the model I have created to map with the response.这是我为 map 创建的 model 和响应。

export interface VatAPI {
  result: EntityResponse;
}

export interface EntityResponse {
  subjects: Entity[];
  requestDateTime: string;
  requestId: string;
}

export interface Entity {
  authorizedClerks: EntityPerson[];
  regon: string;
  workingAddress: string;
  hasVirtualAccounts: boolean;
  statusVat: string;
  krs: string;
  restorationBasis: string;
  accountNumbers: string[];
  registrationDenialBasis: string;
  representatives: EntityPerson[];
  residenceAddress: string;
  registrationDenialDate: Date;
  restorationDate: Date;
  name: string;
  registrationLegalDate: Date;
  removalBasis: string;
  removalDate: Date;
  nip: string;
  partners: EntityPerson[];
  pesel: string;
}

export interface EntityPerson {
  firstName: string;
  lastName: string;
  nip: string;
  companyName: string;
}

Service class to call the https and map the response.服务 class 调用 https 和 map 响应。

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import {
  HttpClientModule,
  HttpClient,
  HttpParams,
} from '@angular/common/http';

@Injectable()
export class ApiService {
  constructor(private httpclient: HttpClient) {}
  getcomments(): Observable<any> {
    return this.httpclient.get(
      'https://wl-api.mf.gov.pl/api/search/nip/7272445205?date=2020-07-27'
    );
  }

}

Here is the app.component.ts which is calling api.service.ts这是调用 api.service.ts 的 app.component.ts

import { Component } from '@angular/core';

import { VatAPI } from './classes/vatapi';
import { ApiService } from './services/api.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  constructor(private ApiService: ApiService) {}

  lstresult: VatAPI;

  // tslint:disable-next-line: use-lifecycle-interface
  ngOnInit(): void {
    this.ApiService.getcomments().subscribe((data) => {
      this.lstresult = data;
    });
  }
}

And my app.comonent.html looks like this而我的 app.comonent.html 看起来像这样

<h2>Get Request (https://wl-test.mf.gov.pl:9091/wykaz-podatnikow/api/search/nip/7272445205?date=2020-07-27)</h2>

<span>{{ lstresult }}</span>

When I serve the project I am getting [object Object] response.当我为项目提供服务时,我得到了 [object Object] 响应。 Where is the mistake I am unable to figure it out plz help我无法弄清楚错误在哪里请帮助

Use the json pipe to see the data.使用json pipe查看数据。

<span>{{ lstresult | json }}</span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM