-1

I use angular http.get method, but my return data is an object type, which has a json attribute, I want to get this json attribute list, how to do it?。。。。

I only want to get json data.. { "errno": 0, "data": { "pageNum": 1, "pageSize": 5, "totalPage": 1, "total": 5, "list": [ { "tgCode": "222", "tgName": "测试002", "tgLevelId": 1, "tgStatus": 1, "tgTypeId": 1, "createUser": "张三", "archiveNote": null, "createTime": "2023-01-10 10:55:44", "archiveTime": null, "operateUserList": "张三,张三,李四,李四,张三,张三,李四,李四" } ] } }

1
  • What did you try and what did your research yield? SO is no replacement for doing research or learning the basics of RxJS. Some code to illustrate your problem is also always helpful. Please take the tour and see How to Ask. Did the answer on your previous question not work?
    – Lukas-T
    Commented Jan 11, 2023 at 14:31

1 Answer 1

0

Without some code it's difficult to determine the issue. But I assume you'd need something like this (from code I had):

  ngOnInit() {
    // assume this is using http service here and is sending the response json like contractData.
    this.contract$ = of(this.contractData).pipe(
      map((r) => r.result.data)
    );
  }

Notice the map operation to map the desired part of the response.

Then in the template, I can get which parts of that data I need:

<div ng-container *ngIf="contract$ | async as response">
  <div class="card" *ngFor="let contract of response">
    <div class="card-header">
      <code>
        <pre>{{ contract.number }}</pre>
      </code>
    </div>
  </div>
</div> 

In my case, "contract" looks structurally similar to your data, like this:

[
  {
    "number": "0065",
    "vendor": "ABC Inc",
    "starts": "2022-12-24"
  },
  {
    "number": "C0062",
    "vendor": "XYZ corp",
    "starts": "2022-12-30"
  },
  {
    "number": "9001",
    "vendor": "Acme International",
    "starts": "2018-09-28"
  },
  {
    "number": "0059",
    "vendor": "Companies R Us",
    "starts": ""
  }
]

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.