ng-table如何使用angular 5从API AWS获取数据

时间:2018-07-16 10:35:16

标签: javascript angular amazon-web-services

我正在使用Angular 5和ng-table,但是如何使用AWS从API获取数据? 我没有任何错误。我可以在控制台上检索数据,但是表中没有数据。

我正在使用以下代码: 参与者

 private data: Array<Participant> = [];
 public constructor(private httpClient: HttpClient, private 
 participantsListService: ParticipantListService) {
 this.length = this.data.length;
 }
public ngOnInit(): void {
this.getJsonData().subscribe(itemsFromGetRequest => {
  // Loop through the items for the HTTP GET request and insert them 
into the data array (the table).
  itemsFromGetRequest.forEach(item => {
    this.data.push(item);
    this.length = this.data.length; // this is for pagination
    this.onChangeTable(this.config);
  });
  });
  }

  public getJsonData(): Observable<any[]> {
  const myHeader = new HttpHeaders();
  return this.httpClient.get<Participant[]>('url here',
  {headers: new HttpHeaders().set('Authorization', '77777')})
  .map((response) => {
   this.data = response; // Here the table is filled with data.
      console.log(this.data);
      return this.data;
  },
   error => console.log('error', error)
  );
  }

0 个答案:

没有答案