Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角材料数据表更新_Angular_Rxjs_Angular Material - Fatal编程技术网

Angular 角材料数据表更新

Angular 角材料数据表更新,angular,rxjs,angular-material,Angular,Rxjs,Angular Material,我用有角度的材料实现了有角度的 我从API中读取数据,并使用以下代码填充表: @ViewChild('filter') filter: ElementRef; dataSource: MyDataSource | null; dataSubject = new BehaviorSubject<any[]>([]); displayedColumns = ['name']; constructor(private appService: Applications

我用有角度的材料实现了有角度的

我从API中读取数据,并使用以下代码填充表:

@ViewChild('filter') filter: ElementRef;

  dataSource: MyDataSource | null;
  dataSubject = new BehaviorSubject<any[]>([]);
  displayedColumns = ['name'];

    constructor(private appService: ApplicationsService) {
    this.appService.getAllApps().subscribe({
      next: value => this.dataSubject.next(value)
    });
  }

  ngOnInit() {
    this.dataSource = new MyDataSource(this.dataSubject);
  }

export class MyDataSource extends DataSource<any[]> {

  constructor(private subject: BehaviorSubject<any[]>) {
    super ();
  }

  connect (): Observable<any[]> {
    return this.subject.asObservable();
  }

  disconnect (  ): void {

  }

}
但是表不会更新

  • 为什么表没有更新
  • 如何根据输入筛选表

  • 一种解决方案是在HTML中定义一个操作列,如下所示:

    <ng-container matColumnDef="actions">
            <mat-cell *matCellDef="let model">
              <button mat-icon-button matTooltip="Edit" (click)="edit(model)">
                <mat-icon>edit</mat-icon>
              </button>
            </mat-cell>
    </ng-container>
    
    }


    请记住,元素和响应必须是同一类型的

    一种解决方案是在HTML中定义一个操作列,如下所示:

    <ng-container matColumnDef="actions">
            <mat-cell *matCellDef="let model">
              <button mat-icon-button matTooltip="Edit" (click)="edit(model)">
                <mat-icon>edit</mat-icon>
              </button>
            </mat-cell>
    </ng-container>
    
    }


    请记住,要素和回答必须是同一类型的

    您的第二个问题将在您在问题中引用的页面中解决。您的第二个问题将在您在问题中引用的页面中解决。
    <ng-container matColumnDef="actions">
            <mat-cell *matCellDef="let model">
              <button mat-icon-button matTooltip="Edit" (click)="edit(model)">
                <mat-icon>edit</mat-icon>
              </button>
            </mat-cell>
    </ng-container>
    
    private edit(element?: Model) {
        // In this case i use Mat-Dialog from edition
        let dialogRef = this.dialog.open(EditDialogComponent,
      {
        panelClass: 'mat-dialog-lg',
        data: { element: element }
      });
    dialogRef.afterClosed().subscribe(response => {
      if (response) {
        // For change the data in the table list you have to assign the response to your element
        element = response;
      }
    });