Angular 12 - Mat-Dialog 不显示表中的值

我正在尝试使用此服务 URI 创建一个简单的基于 12 角的 CRUD 应用程序 - https://api.github.com/repos/angular/angular/issues

我有一个这样的模型:

export class Issue {
  id: number;
  title: string;
  state: string;
  url: string;
  created_at: string;
  updated_at: string;
  author_association: string;
}

在 app.component.html 中,我的表格组件列如下:

    <ng-container matColumnDef="author_association">
        <mat-header-cell *matHeaderCellDef mat-sort-header>Author Association</mat-header-cell>
        <mat-cell *matCellDef="let row"> {{row.author_association}}</mat-cell>
    </ng-container>

数据显示在表格中,如下所示:

Angular 12 - Mat-Dialog 不显示表中的值

还有两个对话框组件(删除/编辑)。

import { MAT_DIALOG_DATA,MatDialogRef } from '@angular/material/dialog';
import {Component,Inject} from '@angular/core';
import {DataService} from '../../services/data.service';


@Component({
  selector: 'app-delete.dialog',templateUrl: '../../dialogs/delete/delete.dialog.html',styleUrls: ['../../dialogs/delete/delete.dialog.css']
})
export class DeleteDialogComponent {

  constructor(public dialogRef: MatDialogRef<DeleteDialogComponent>,@Inject(MAT_DIALOG_DATA) public data: any,public dataService: DataService) { }

  onNoClick(): void {
    this.dialogRef.close();
  }

  confirmDelete(): void {
    this.dataService.deleteIssue(this.data.id);
  }
}

import { MAT_DIALOG_DATA,Inject} from '@angular/core';
import {DataService} from '../../services/data.service';
import {FormControl,Validators} from '@angular/forms';

@Component({
  selector: 'app-baza.dialog',templateUrl: '../../dialogs/edit/edit.dialog.html',styleUrls: ['../../dialogs/edit/edit.dialog.css']
})
export class EditDialogComponent {

  constructor(public dialogRef: MatDialogRef<EditDialogComponent>,public dataService: DataService) { }

  formControl = new FormControl('',[
    Validators.required
    // Validators.email,]);

  getErrorMessage() {
    return this.formControl.hasError('required') ? 'Required field' :
      this.formControl.hasError('email') ? 'Not a valid email' :
        '';
  }

  submit() {
    // emppty stuff
  }

  onNoClick(): void {
    this.dialogRef.close();
  }

  stopEdit(): void {
    this.dataService.updateIssue(this.data);
  }
}

问题: 上述两个对话框中都缺少作者关联的数据。例如:

Angular 12 - Mat-Dialog 不显示表中的值

问题:我在这里遗漏了什么?或者我在这里做错了什么?

如果需要,我可以提供更多详细信息。以及可直接运行的 project is available here

jahy988 回答:Angular 12 - Mat-Dialog 不显示表中的值

row.author_association 在 startEdit() 函数中丢失。在按钮中添加 row.author_association 应该可以解决您的问题

<button mat-icon-button color="accent" (click)="startEdit(i,row.id,row.title,row.state,row.url,row.created_at,row.updated_at,row.author_association)">
本文链接:https://www.f2er.com/800.html

大家都在问