Angular 角度8接口+;休息反应

Angular 角度8接口+;休息反应,angular,rest,interface,Angular,Rest,Interface,如何在组件html中显示(resultData、correlationId、errors) Rest Json响应: Json响应的接口(servi.ts)。我用它来“转换” 如果我在component.html中使用类似的内容 <div> <h3>Something Something</h3> <ul class="items"> <li *ngFor="let res of todos.resultData">

如何在组件html中显示(resultData、correlationId、errors)

  • Rest Json响应:
  • Json响应的接口(servi.ts)。我用它来“转换”
  • 如果我在component.html中使用类似的内容

    <div>
    
      <h3>Something Something</h3>
    
    
      <ul class="items">
        <li *ngFor="let res of todos.resultData">
          {{res}}
        </li>
      </ul>
    </div>
    
    
    什么东西
    
      {{res}}
    它会给我:
    1.什么东西 [对象对象],[对象对象对象],[对象对象],[对象对象对象],[对象对象]

  • 控制台中ngFor中使用的resultData为:“ERROR TypeError:无法读取未定义的属性'resultData'”

  • 在服务中,将http调用更改为:

    return this.http.get<SubServices>(this.sotUrl); 
    
    以及您的模板:

    <div>
    
      <h3>Something Something</h3>
    
    
      <ul class="items">
        <li *ngFor="let res of todos.resultData">
          {{res[0].subservice}}
        </li>
      </ul>
    </div>
    
    
    什么东西
    
      {res[0]。子服务}

    在您的服务中将您的http调用更改为:

    return this.http.get<SubServices>(this.sotUrl); 
    
    以及您的模板:

    <div>
    
      <h3>Something Something</h3>
    
    
      <ul class="items">
        <li *ngFor="let res of todos.resultData">
          {{res[0].subservice}}
        </li>
      </ul>
    </div>
    
    
    什么东西
    
      {res[0]。子服务}

    在您的回答中,resultData是一个数组的数组。所以您需要将以下代码放入html中

    <ul class="items">
        <li *ngFor="let res of todos.resultData[0]">
          {{res}}
        </li>
    </ul>
    

    如果你只把{{res}}放在DOM中,它会给出[object]。如果您想显示整个对象,您需要在响应中提供类似管道的{{res | json}resultData是数组的数组。所以您需要将以下代码放入html中

    <ul class="items">
        <li *ngFor="let res of todos.resultData[0]">
          {{res}}
        </li>
    </ul>
    

    如果你只把{{res}}放在DOM中,它会给出[object]。如果您想显示整个对象,您需要提供类似管道的{{res|json}

    好的,我将组件更改为:

    import { Component, OnInit } from '@angular/core';
    import {SotService} from '../sot.service';
    import {ResultDDD, SubServices} from '../servi';
    
    
    @Component({
      selector: 'app-sotlist',
      templateUrl: './sotlist.component.html',
      styleUrls: ['./sotlist.component.css']
    })
    export class SotlistComponent implements OnInit {
    
      todos: SubServices;
      public resul: ResultDDD[];
      constructor( private sotService: SotService) {}
    
      ngOnInit() {
        this.getSubServices();
      }
    
       getSubServices() {
         this.sotService.getSubServices()
           .subscribe(
             (data: SubServices) =>  {
               this.todos = data;
               this.resul = this.todos.resultData[0];
               console.log(this.todos);
             }
           );
      }
    }
    
    
    现在,关于我使用的html:

    <div>
    
      <h3>Something Something</h3>
    
    
      <ul class="items">
        <li *ngFor="let res of resul">
          {{res.ssrefitem}}
        </li>
      </ul>
    </div>
    
    
    什么东西
    
      {{res.ssrefitem}}
    没有控制台错误,并且显示正确(并且在html端自动完成)。。。
    Thks tshoemake和Parth Dhancha.

    好的,我将组件更改为:

    import { Component, OnInit } from '@angular/core';
    import {SotService} from '../sot.service';
    import {ResultDDD, SubServices} from '../servi';
    
    
    @Component({
      selector: 'app-sotlist',
      templateUrl: './sotlist.component.html',
      styleUrls: ['./sotlist.component.css']
    })
    export class SotlistComponent implements OnInit {
    
      todos: SubServices;
      public resul: ResultDDD[];
      constructor( private sotService: SotService) {}
    
      ngOnInit() {
        this.getSubServices();
      }
    
       getSubServices() {
         this.sotService.getSubServices()
           .subscribe(
             (data: SubServices) =>  {
               this.todos = data;
               this.resul = this.todos.resultData[0];
               console.log(this.todos);
             }
           );
      }
    }
    
    
    现在,关于我使用的html:

    <div>
    
      <h3>Something Something</h3>
    
    
      <ul class="items">
        <li *ngFor="let res of resul">
          {{res.ssrefitem}}
        </li>
      </ul>
    </div>
    
    
    什么东西
    
      {{res.ssrefitem}}
    没有控制台错误,并且显示正确(并且在html端自动完成)。。。
    Thks tshoemake和Parth DHANKCHA.

    你的控制台.日志(这个.todos)是什么样子的?你的控制台.日志(这个.todos)是什么样子的?Thks#tshoemake用于快速响应。但在控制台日志上,它仍然给我“无法读取未定义的属性'resultData'。我在html中使用它:
      {res.ssrefitem}
    您应该将html.thks中的这个*ngFor=“let res of todos.resultData[0]”更改为这个*ngFor=“let res of todos.resultData”。但在控制台日志上,它仍然给我“无法读取未定义的属性'resultData'。我在html中使用它:
      {res.ssrefitem}
    您应该在html中将这个*ngFor=“let res of todos.resultData[0]”更改为这个*ngFor=“let res of todos.resultData”。目标是使用resultData中的内容,并显示它。如果我使用这个(在html中){{res.ssrefitem}它将给出响应的数字(在字段ssrefitem上)。但在控制台上,它会给出“SotlistComponent.html:7错误类型错误:无法读取未定义的属性'resultData'”的“为什么?目标是,使用resultData中的内容,显示它。如果我使用这个(在html中){{res.ssrefitem}它将给出响应的数字(在字段ssrefitem上)。但在控制台上,它会告诉我“SotlistComponent.html:7错误类型错误:无法读取未定义的”Why?