Angular 无错误,但未在Mat表上显示数据

Angular 无错误,但未在Mat表上显示数据,angular,typescript,frontend,Angular,Typescript,Frontend,我想将php mysql中的数据显示到我的angular mat表中。我正在使用angular CLI 8.1.0。下面是我的代码,谁能帮我找出实际的错误。 我通过PHP和MYSQL制作了RESTAPI,当我遇到postman时,它以json格式给出了数据库记录。但是我不能把它展示在我的垫子上 api.service.ts 供应商行动.component.ts 如果要将“可观察对象”中的数组与异步管道一起使用,请将代码更改为: export class VendorActionCompo

我想将php mysql中的数据显示到我的angular mat表中。我正在使用angular CLI 8.1.0。下面是我的代码,谁能帮我找出实际的错误。 我通过PHP和MYSQL制作了RESTAPI,当我遇到postman时,它以json格式给出了数据库记录。但是我不能把它展示在我的垫子上

api.service.ts

供应商行动.component.ts


如果要将“可观察对象”中的数组与异步管道一起使用,请将代码更改为:

    export class VendorActionComponent {

      displayvendors : any;
      constructor(private router:Router,public apiService:ApiService){}

      ngOnInit()
      {
        this.displayvendors = this.apiService.userList();
      }
   ...
    }

如果要将“可观察对象”中的数组与异步管道一起使用,请将代码更改为:

    export class VendorActionComponent {

      displayvendors : any;
      constructor(private router:Router,public apiService:ApiService){}

      ngOnInit()
      {
        this.displayvendors = this.apiService.userList();
      }
   ...
    }

将其添加到组件中

从'@angular/material'导入{MatTableDataSource}

变量的类型应为MatTableDataSource

displayvendors:MatTableDataSource

并将从API调用中获得的数组分配给
displayvendors
,如下所示

this.apiService.userList().subscribe(displayvendors=>{
this.displayvendors=新的MatTableDataSource(displayvendors);
})


这对我有用。想法是将数组转换为mat table结构,然后是角材质,将其添加到组件中

从'@angular/material'导入{MatTableDataSource}

变量的类型应为MatTableDataSource

displayvendors:MatTableDataSource

并将从API调用中获得的数组分配给
displayvendors
,如下所示

this.apiService.userList().subscribe(displayvendors=>{
this.displayvendors=新的MatTableDataSource(displayvendors);
})


这对我有用。想法是将数组转换为mat表结构,后面是角度材质

尝试:
this.apiService.userList().subscribe(displayvendors=>{this.displayvendors=displayvendors;})并从您的计算机中删除
async
管道html@BartoszTermena没用。没有结果您从html中删除了
| async
@BartoszTermena是的,我删除了:
this.apiService.userList().subscribe(displayvendors=>{this.displayvendors=displayvendors;})并从您的计算机中删除
async
管道html@BartoszTermena没用。没有结果您是否从html中删除了
| async
@BartoszTermena是我删除了
<div class="purchases-style">
    <div>
        <table mat-table [dataSource]="displayvendors" class="mat-elevation-z1">
        <ng-container matColumnDef="id">
            <th mat-header-cell *matHeaderCellDef> Vendor ID </th>
            <td mat-cell *matCellDef="let element"> {{element.id}} </td>
        </ng-container>

        <ng-container matColumnDef="changeColumn">
            <th mat-header-cell *matHeaderCellDef> Change Column </th>
            <td mat-cell *matCellDef="let element"> {{element.changeColumn}} </td>
        </ng-container>

        <ng-container matColumnDef="type">
            <th mat-header-cell *matHeaderCellDef> Change Type </th>
            <td mat-cell *matCellDef="let element"> {{element.type}} </td>
        </ng-container>

        <ng-container matColumnDef="timestamp">
            <th mat-header-cell *matHeaderCellDef> Timestamp </th>
            <td mat-cell *matCellDef="let element"> {{element.timestamp}} </td>
        </ng-container>

        <ng-container matColumnDef="status">
            <th mat-header-cell *matHeaderCellDef> Status </th>
            <td mat-cell *matCellDef="let element"> {{element.status}} </td>
        </ng-container>

        <tr mat-header-row *matHeaderRowDef="['id','changeColumn','type','timestamp','status']"></tr>
        <tr class="rowhover" (click)="displayData(row)" mat-row *matRowDef="let row; columns: ['id','changeColumn','type','timestamp','status']"></tr>
        </table>

         <mat-paginator [length]="100" [pageSize]="10" [pageSizeOptions]="[5, 10, 25, 100]" class="mat-elevation-z1">
         </mat-paginator>
     </div>
     <router-outlet></router-outlet>
</div>
export interface Displayvendor {
    id: number;
    changeColumn: string;
    type: string;
    timestamp: string;
    status: string;
  }
    export class VendorActionComponent {

      displayvendors : any;
      constructor(private router:Router,public apiService:ApiService){}

      ngOnInit()
      {
        this.displayvendors = this.apiService.userList();
      }
   ...
    }