【问题标题】:Integrate mat-table with AngularFirestore将 mat-table 与 AngularFirestore 集成
【发布时间】:2017-10-24 21:04:15
【问题描述】:

我想将 https://material.angular.io/ 的 mat-table 与 angularfire2/firestore https://github.com/angular/angularfire2 集成,有点想法,我很迷茫

最好的尊重

【问题讨论】:

    标签: angular-material angularfire2


    【解决方案1】:

    这就是简单表格的方法。

    在你的 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() { }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-20
      • 1970-01-01
      • 2019-08-31
      • 2021-05-16
      • 1970-01-01
      • 2020-02-23
      相关资源
      最近更新 更多