【发布时间】:2021-10-23 21:19:41
【问题描述】:
numList: any[]=[];
addnumber() {
const dialogRef = this.dialog.open(NumberpopUpComponent, {
width: "500px",
disableClose:true
});
dialogRef.afterClosed().subscribe((result) => {
this.numList = this.NoList; //NoList is list of input value inside popup component
this.numList.push(result);
});
}
HTML:
<button type="button" (click)="addnumber()">
Add Number
</button>
【问题讨论】:
-
这里为什么需要
this.NoList,你从哪里得到这个列表?这是来自NumberpopUpComponent吗?那么你如何在你的组件中使用this来访问它呢? -
感谢您的回复。我们需要 NoList,因为我们将该 NoList 数组分配给 numList 数组。这个 numList 数组是动态形式的模型。这就是我们访问字段的方式。 NoList 是一个在 NumberpopUpComponent 中定义的数组。无论用户在输入字段中给出什么,都将存储在 NoList 数组中。请帮助我如何最好地做到这一点。提前致谢
-
好的。因此,您需要从
NumberpopUpComponent获取 NoList。当用户点击保存按钮时,您需要将 NoList 和文本框中的值传递给afterClosed()订阅。 -
您将
NoList分配给numList,并将响应推送到numList。当您单击保存按钮时,numList将包含NoList+ 文本框中的最后一个值。我说的对吗? -
是的。但这里的问题是它没有显示在该下拉列表中。下拉菜单显示为空
标签: angular angular8 multi-select populate input-field