简体   繁体   English

Mat-Dialog 传递数组并填充它 Angular

[英]Mat-Dialog Passing Array and Populate It Angular

So here is my question I will input a value in the QTY text field.所以这是我的问题,我将在 QTY 文本字段中输入一个值。 Mat dialog will pop up that shows the number of quantities that I inputted.将弹出 Mat 对话框,显示我输入的数量。 How do you iterate an object/data in afterclosed?你如何在afterclose中迭代一个对象/数据? and populate it to the setItem?并将其填充到setItem? I get the result, but it won't iterate it pass to the setItem how to do it?我得到了结果,但它不会迭代它传递给setItem怎么做? this is what I did so far这就是我到目前为止所做的

https://stackblitz.com/edit/mat-dialog-example-2akxdg https://stackblitz.com/edit/mat-dialog-example-2akxdg

updated: i can get the qty, but i can't get what i input in mat-dialog更新:我可以获得数量,但我无法获得我在 mat-dialog 中输入的内容

Actually, you are not sending your data from mat-dialog when it is closed.实际上,当mat-dialog关闭时,您并没有从它发送数据。

in the alter-dialog.component.ts file you're just sending qty on save()alter-dialog.component.ts文件中,您只是在save()上发送 qty

//your method which is not sending the required data
save() {
    this.dialogRef.close(this.data.qty);
  }

you need to send your inputted data too, like this你也需要发送你输入的数据,像这样

//save method that is returning required data
save() {
    this.dialogRef.close(this.fg.value);
    //fg is your form, it has qty too, so no need to send qty separately
  }

in app.component.ts you need to iterate properly afterclose , result itself is not an array, actually, it is an object.app.component.ts中你需要在 close 之后正确aftercloseresult本身不是一个数组,实际上它是一个 object。 displayArray is the actual array that is present in the result object. displayArrayresult object 中存在的实际数组。 you need to iterate like this你需要像这样迭代

dialogRef.afterClosed().subscribe((result) => {
      console.log('qty' + result.qty);
      for (let i = 0; i < result.displayArray.length; i++) {
        this.setItem.push(this.CreatesetItem(result.displayArray[i].MoreItem));
      }
    });

click here to see Stackblitz example with your expected answer 单击此处查看带有您预期答案的 Stackblitz 示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM