因此,基本上我创建了自己的组件,它是可筛选的,可以选择将新项添加到pickListItems中。问题是,我想让输入值作为formControl,但即使我将formGroup传递给子对象,也会出错。
因此示例代码如下所示:
<form [formGroup]="formGroup">
some stuff here to generate form fields, one of fields is my component with
select:
<app-add-picklist
[field]="field"
在过去的几个月里,ControlValueAccessors突然出现在我的脑海中,我有点不明白为什么或者什么时候应该使用它们,而不是在我的反应性表单中使用@Input。
下面是我到目前为止如何使用反应性表单的示例代码:
@Component({
selector: 'app-my-component',
template: `<input [formControl]="form.get('specificControlName')" />`
// or the alternative method of [formGroup
While creating a reactive forms in angular we why we need to use formBuilder instead of FormGroup when we can make reactive forms using either of them.
Here i also provided what i am trying to ask
maintenanceForm: FormGroup;
ngOnInit() {
this.maintenanceForm = new FormGroup({
'value
我在parent formGroup中有一个formControl (电台),并想在formArray中使用它。使用情况是问题有多个选项(formArray),希望有单选按钮,每个选项选择正确的答案(只有一个)
JS
private createForm() {
this.form = new FormGroup({
question: new FormControl('', Validators.required),
correctOption: new FormControl(false),
options: new
在Ionic2 / Angular2中,我正在努力让FormGroup和FormGroupName与嵌套的Components一起工作,不断收到像这样的错误。
Cannot find control with path: 'location -> latitude'
Form页面呈现一个动态的字段列表。
<form [formGroup]="formGroup" (ngSubmit)="postForm()">
<ion-list>
<ion-item *ngFor="let field o
我通过表单构建器使用rest api结果数组设置表单
这是我的表单生成器代码
this._inspectionService.getChecklists(this.truckParam)
.subscribe(
res=> {
this.checklists = res;
let inspectionform: FormGroup;
let checkinputs: FormArray = new FormArray([]);
for (let i = 0; i < this.checklists.length; i++
我有这样的东西
let formGroup = new FormGroup({
operationalAM: new FormGroup({
endTime: new FormControl('')
}),
operationalPM: new FormGroup({
startTime: new FormControl('')
})
});
我正试图像这样为endTime和startTime设置值
formGroup.controls.operationalAM.value.endTime.setValue('1300&
我有一个呈现标签的组件,并将输入元素作为子元素传递如下:
<FormGroup labelFor="my-formgroup-id">
<input id="my-formgroup-id" /> // I don't want to duplicate this id manually here but take it from the `labelFor prop of the `<FormGroup>` it's wrapped in
</FormGroup>
如何从id中获取Form
我已经创建了一个自定义验证器,它如下所示:
export class TestRequestComponent implements OnInit {
noSymptomSelected: boolean = true;
symptoms: FormGroup = new FormGroup({
symptom1: new FormControl(false),
symptom2: new FormControl(false),
symptom3: new FormControl(false)
}, this.validateMe)
form =
我正在尝试创建一个与反应式表单集成的组件。由于这个特定的字段将在整个应用程序中被重用多次,如果我能够做到这一点,它将真的对我有所帮助。我的想法是,我将表单放在一个页面中(这是一个离子项目),这个页面将包含FormGroup。在此页面中,我将插入组件,并将FormGroup和指向该组件的路径传递给它。
表单:
form: FormGroup = new FormGroup({
group1: new FormGroup({
group2: new FormGroup({
control: new FormControl('
有没有办法在不删除先前添加的任何验证器的情况下,将验证器添加到表单组并仅将其添加到表单组。 假设我有一个很大的FormGroup,在某个点上我需要添加一个自定义验证器。setValidators删除可能已添加到其中的任何验证器。formGroup.serValidators([customValidation, fromGroup.validator])在自定义验证null中创建group。有什么想法吗? 这是我到目前为止所得到的: const customValidation(thing, otherThing): ValidatorFn {
// The group is null i