标签: angular2-formbuilder

(Angular 5)错误:找不到名称为的表单控件:

我正在尝试编辑表单,当我想显示要编辑的值时,使用 setValue 出现错误“错误错误:找不到名称为采购的表单控件。

组件.ts

ngOnInit() {
  this.form = new FormGroup({
      customer: new FormGroup({
        name: new FormControl(),
        lastname: new FormControl(),
        address: new FormControl(),
        phone: new FormControl()
      }),
      createdAt: new FormControl(),
      purchases: new FormArray([])
  });
}
Run Code Online (Sandbox Code Playgroud)

我的编辑功能

onEdit(invoice) {    
  this.form.setValue(invoice)   
}
Run Code Online (Sandbox Code Playgroud)

组件.html

<div class="col-md-8">
    <div formGroupName="customer">
      <h3>Customer</h3>
      <label>Name: <input class="form-control" type="text" formControlName="name"> </label>
      <label>Last Name:<input class="form-control" type="text" formControlName="lastname"></label>
      <label>Phone:<input class="form-control" type="text" formControlName="phone"></label>
      <label>Address:<input class="form-control" type="text" formControlName="address"></label>
   </div>
   <div><li formArrayName="purchases"></li></div>
</div>
Run Code Online (Sandbox Code Playgroud)

在 StackBlitz 中查看

控制台中的值

安慰

typescript angular2-formbuilder angular angular5

1
推荐指数
1
解决办法
4010
查看次数

带有ng2-bootstrap日期选择器的模型驱动表单

我环顾四周,找不到任何确定的方法-您可以将ng2-bootstrap datepicker与Angular2模型驱动的表单一起使用,还是仅适用于模板表单?

该文档介绍了选择器,以便您可以按以下方式使用它(作为示例):

<datepicker [(ngModel)]="startDate" ></datepicker>
Run Code Online (Sandbox Code Playgroud)

...似乎确实有效。理想情况下,我想这样使用它:

<datepicker formControlName="startDate" ></datepicker>
Run Code Online (Sandbox Code Playgroud)

...但似乎开箱即用。有没有办法将此模块与模型驱动的表单一起使用?如果没有,是否存在一种适用于模型驱动表单的合理替代方案?(我也尝试过ng2-datepicker,但是有一个突出的错误使SystemJS难以使用,这很不幸,因为它看起来很光滑)。

datepicker angular2-forms ng2-bootstrap angular2-formbuilder angular

0
推荐指数
1
解决办法
2974
查看次数

以嵌套反应形式使用setControl

我想知道当我在另一个formBuilder组中有一个数组时,如何使用反应形式使用“ setControl”和“ get”。例如:

this.formulario = this.formBuilder.group({
  title: [this.racPessoa.title, [Validators.required]],
  description: [this.racPessoa.description, [Validators.required]],
  person: this.formBuilder.group({
    idPerson:[this.racPessoa.person.idPerson],
    name:[this.racPessoa.person.nome],
    personDocument: this.formBuilder.array([])
  }),
});
Run Code Online (Sandbox Code Playgroud)

在上述情况下,如果我想使用“标题”,则可以编写:

this.formulario.setControl('title', something);
this.formulario.get('title');
Run Code Online (Sandbox Code Playgroud)

但是当我要使用一个人内部的“ personDocument”来处理时,我不知道如何在上面写两个句子

我尝试使用:

this.formulario.setControl('person.personDocument', something);
this.formulario.get('person.personDocument')
Run Code Online (Sandbox Code Playgroud)

但这是行不通的。

angular2-forms angular2-formbuilder angular angular-reactive-forms

0
推荐指数
1
解决办法
4571
查看次数

角形式:patchValue后无法在字段中键入

我有一个要从数据表切换的表格。当我使用patchValue预填写表单时,无法编辑该字段的内容。未填充patchValue的字段是可更新的。

这是控制器设置

@Input() signalMutate: Signal;

  signalForm: FormGroup;
  loading = false;
  submitted = false;
  error: string;
  formSignalValue: Signal;

  constructor(
    private formBuilder: FormBuilder,
    private router: Router,
    private authenticationService: AuthenticationService,
    private userService: UserService

  ) { }

  ngOnInit() {
    this.signalForm = this.formBuilder.group({
      title: [''],
      description: ['', Validators.required],
      problem: ['', Validators.required],
      value: ['', Validators.required],
      requestor: ['', Validators.required],
      label: ['']
  });


  }

  ngAfterContentChecked(){

    if(this.signalMutate) { 

        this.signalForm.patchValue(this.signalMutate);

    }

  }
Run Code Online (Sandbox Code Playgroud)

知道为什么会这样吗?

谢谢!

angular2-formbuilder angular

0
推荐指数
1
解决办法
38
查看次数