首页 > 解决方案 > 我如何以角度显示这些对象

问题描述

下面是JSN数据的图片:

从 api 接收 json 数据

网络服务.ts

 myQuote = 'http://quotes.rest/qod.json';

 getQuotes(){
  return this.http.get(this.myQuote).subscribe(data => {
    // data = const quotes;  
    console.log(data)
  });
}

home.component.ts

@Component({
  selector: 'messages',
  template: ' here {{contents?.quotes[0].quote}}'
})

export class MessagesComponent {
constructor(private webService: webServices){}

showQuotes(){
    this.webService.getQuotes();
    var items = {}
  }
  ngOnInit(){
    console.log(this.showQuotes())

  }
} 

标签: angularobject

解决方案


根据假设,根据您的屏幕截图:

HTML:

<div *ngFor="let obj of data.contents.quotes">
    <div> {{obj.propertyName_that_you_want_display }} </div>
    <h2>Options:</h2>
    <div *ngFor="let tag of obj.tags">
        {{tag}}
    </div>
</div>

A Working Demo


推荐阅读