[英]How to display the object coming from API response using angular material table?
我有一個來自響應的 object,看起來像. 這是一個動態鍵值對
{
"name1": "value1",
"name2": "value2",
"name3": "value3"
............
............
}
我想由此生成一個材料表。 我想知道如何將響應放入我的組件文件中。
我在我的服務文件中得到響應。
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
import { map } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class ApiService {
private headers = new Headers({ 'Content-Type': 'application/json' });
url: string = '';
constructor(private http:HttpClient) {
this.url = "https://beta.randomapi.com/api/3141b5683af0edf576dabdb50ef1ff64?fmt=prettyraw&sole";
}
public getData() {
return this.http.get(this.url )
.pipe(map((res: Response) => {
return res.json();
}));
}
}
首先,數據源必須是一個數組,您提到的 json 應該代表表中的一行。 這是一個使用它的示例。 這會給你一個前進的方向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.