2017-10-17 29 views

回答

5

这是你如何简单做表。

在你的html文件中把这个。

<mat-table [dataSource]="myData"> 

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

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

    <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row> 
    <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row> 

</mat-table> 

在JavaScript把这个

import { AngularFirestore} from 'angularfire2/firestore'; 

    export class MyComponent{ 
     displayedColumns = ['name', 'description'];  
     myData; 

     constructor(private afs: AngularFirestore) { 
     this.myData= new MyDataSource(this.afs); 
     } 

    } 

    export class MyDataSource extends DataSource<any> { 
     constructor(private afs: AngularFirestore) { 
     super(); 
     } 
     connect(): Observable<any[]> { 
     return this.afs.collection('products').valueChanges(); 
     } 

     disconnect() { } 
    } 
+0

作品完美,非常感谢你 –

+0

@PetoKalea如果它完美的作品将其标记为答案 –