angular - Angular Reactive Forms FormArray - 添加按钮以打开另一个弹出表单
问题描述
我正在尝试实现以下场景。我有一个带有输入控件的表单。一个元素是formarray。这个表单数组的输入控件很少。添加按钮以创建此表单数组。单击添加按钮时,应出现一个新的弹出窗口或模式来填写值。是否可以使用 ngx bootstrap 或 angular material 或 ngtemplateOutlet 或 ngcontainer。请提供建议。是否可以在模型中收集整个提交。
解决方案
这是完整的工作StackBlitz 链接
首先你需要你的表单数组组件让我们这么说......
ngOnInit() {
this.form = this.fb.group({
questions: this.fb.array([
this.fb.group({
questionNumber: new FormControl(this.data.questionCount + 1, { validators: [Validators.required] }),
type: new FormControl('paragraph'),
text: new FormControl('', { updateOn: 'blur', validators: [Validators.required, Validators.maxLength(30)]})
}),
]),
})
}
在 app.component 中,您可以取回数据并像这样打开 Mat-Dialog ...
openDialog() {
const dialogRef = this.dialog.open(AddQuestionDialog, {
width: '600px',
data: { questionCount: 0 }
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed', result);
this.animal = result;
});
对于更完整的工作示例,您可以在上面的 stack-blitz 链接中找到...
推荐阅读
- stm32 - stm32H474I 无法调试
- appium - 对于使用 react native 创建的 iOS 应用程序,无法使用 xpath 结尾在 appium 中定位元素
- javascript - 使用从 JavaScript 传递的值数组填充下拉列表
- git - Gerrit 匹配关键字的一些代码搜索工具
- router - 无法从 wifi 连接(SMB 或 NFS)到 LAN 上的有线 - Arris 路由器(Cox)
- c++ - c++ 中的设置操作(更新现有值)
- python-3.x - 与日期列的逻辑比较在 Pandas 数据框中不起作用
- python-3.x - 处理“\000”、“\n”、“\r”、“bellchars”等特殊字符;在 pyspark 数据框中
- javascript - 表单更新后如何在html中重新加载特定区域
- react-native - 如何查看反应原生组件的可用样式