我在angular的form中创建了一个formArray。 当我修补具有值为数组的tasks的对象时,此属性似乎被忽略且未设置。 不出所料,名字被更改了。但任务并非如此。为什么? 我不想捕获特定的元素并使用setValue或类似的东西,我只想有一个对象,angular将调查这个对象并匹配值和字段。 The code in stackblitz.com import { Component, VERSION } from "@angular/core";
import { FormGroup, FormControl, FormArray } from "@angul
我不明白FormGroup、FormControl、FormArray在Angular中是如何工作的 我的错误是: Type '{ question: FormControl; multi: true; choices: FormArray; }' is not assignable to type 'AbstractControl'.
Object literal may only specify known properties, and 'question' does not
exist in type 'AbstractCon
我有一个使用FormArray的带有动态嵌套表单的Angular表单。我从另一篇文章中得到了嵌套表单的想法。我正在尝试将嵌套表单输出到一个具有rowspan的html表中。我想我已经正确地计算出了结构,但是当我尝试将嵌套表单呈现到一个表中时,标题被推到了右边,第一列变成了整个输出的列。 我这里有一个stackblitz条目:https://stackblitz.com/edit/angular-ivy-4zjniz?file=src/app/app.component.ts 当窗体第一次呈现时,它显示如下:First time on component image 然后,当我点击Add Se
当我试图循环formArray的控件时,我得到一个错误,formControlName必须在formGroup中,但我在formArray中没有formGroup。html中的代码如下所示 enter image description here 在.ts中是这样的 enter image description here 当我没有formGroup但Angular想要提供formGroup时,我该如何解决这个问题
在动态添加的FormGroup中,我似乎无法将焦点设置在输入字段上:
addNewRow(){
(<FormArray>this.modalForm.get('group1')).push(this.makeNewRow());
// here I would like to set a focus to the first input field
// say, it is named 'textField'
// but <FormControl> nor [<AbstractControl&g
我动态地将包含FormGroups的FormControls添加到FormArray中,并将表单的控件显示在UI中作为输入字段。我想计算在UI中添加的每个sectionContent字段中输入的字符。这在只有一个FormGroup时是完全可能的,因为我可以订阅valueChanges方法,将值的长度传递给变量,然后在UI中插入变量。但是,是否可以使用多个动态添加的FormGroups及其FormControls呢?问题是,每个FormGroup都需要在html代码中注入一个新变量,我不确定这是可能的。也许还有另一种方法可以在UI中的多个字段中计算字符呢?
HTML:
<div class
我在一个Angular 7应用程序中使用模型驱动表单,其中一个表单允许用户动态添加/删除一组字段。这是我所指的视觉参考:
这是我使用的FormModel:
this.formModel = new FormGroup( {
id : new FormControl(''),
name : new FormControl('', Validators.required),
comment : new FormControl(''),
options : new FormControl(3),
我正在努力建立具有这种结构的动态形式:
Form
-|FormGroup
--|FormArray
---|FormGroup
----|FormControl
----|FormArray
-----|FormGroup
------|FormControl <-- Problem that I cannot bind this form control to input
------|FomrControl <-- Problem that I cannot bind this form control to input
在两个指定的控件上,我得到错误。
Cannot find
:,我正在构建一个可重用的FormGroups中继器(reactive ),其中中继器的通用部分提供添加/删除控件和逻辑,所有想要使用它的组件只需要提供必须重复的模板。我查过了
它展示了如何用模板驱动的方式来完成这样的事情。
:,我附加到<template>中的控件的formControlName指令不会被中继器的通用部分接收到:
Error: Cannot find control with name: 'id'
at _throwError (https://unpkg.com/@angular/forms/bundles/forms.umd.js