【问题标题】:In Angular reactive forms can i add a nested form without an array?在 Angular 反应式表单中,我可以添加没有数组的嵌套表单吗?
【发布时间】:2017-10-20 03:22:02
【问题描述】:
    this.parentForm = this._fb.group({
     testControl1: [],
     testControl2: [],
     testChildForm1: this._fb.group({
       testChildControl1: [],
       testChildControl2: []
     })
   )};

对于上面的父表单,它包含两个表单控件和一个嵌套的子表单组。

我想访问下面的子表单的值

this.parentForm.controls['testChildForm1'].controls.testChildControl1

但无法访问子窗体的控件,因为 TS 给出错误 “AbstractControl”类型上不存在属性“控件”

【问题讨论】:

    标签: angular angular-reactive-forms


    【解决方案1】:

    这样的事情怎么样:

    this.parentForm.get(`testChildForm1.testChildControl1`).value
    

    【讨论】:

      猜你喜欢
      • 2018-07-04
      • 2018-08-06
      • 2019-02-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多