简体   繁体   English

角值形式的色块值

[英]Patchvalue in angular form

I my angular application, i am using angular dynamic form in which i am patching value with some json. 我的角度应用程序,我正在使用角度动态形式,其中我用一些json修补值。

  data =
  {
    firstName:"Eliseo",
    lastName:"Plunker",
    myArray:
    [
    {
    emailAddress:"eliseo@plunker.com",
    brave:"solid"
    },
    {
    emailAddress:"eliseo@plunker.org",
    brave:"great"
    }
    ]
  }

Patchvalue function: 拍值函数:

  fillData()
  {
    this.form = this.qcs.toFormGroup(this.questions);
    for (let i=0;i<this.data.myArray.length;i++)
    {
      this.addControls('myArray');
    }
    //Use patchValue
    this.form.patchValue(this.data);

  }

Here in this function, i want to patch only the myArray values and not the firstName and lastName . 在此功能中,我只想修补myArray值,而不是firstNamelastName

I have tried with this.data.myArray 我已经尝试过this.data.myArray

    this.form.patchValue(this.data.myArray);

But it doesn't work. 但这是行不通的。

The working stackblitz : https://stackblitz.com/edit/angular-x4a5b6-wztvq9 工作中的stackblitzhttps : //stackblitz.com/edit/angular-x4a5b6-wztvq9

Click over Fill Form button in the above demo to get the patched values in the form.. 在上面的演示中单击“ 填写表单”按钮,以获取表单中的修补值。

Kindly help me to patch only the myArray value and leave others empty.. 请帮助我仅修补myArray值,并将其他值留空。

Try this to patch myArray values 试试这个补丁myArray值

this.form.patchValue({
  'myArray' : this.data.myArray
});

Hope this helps!! 希望这可以帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 角度反应形式错误的arrayGroup的patchValue - angular reactive form wrong patchValue of arrayGroup Angular 8:Reactive Form Automap 和 PatchValue Set Member data - Angular 8: Reactive Form Automap and PatchValue Set Member data 在 Angular 12 反应形式中使用 patchValue 绑定表单数组的最佳方法 - Best way to bind form array using patchValue in Angular 12 reactive form angular 6 patchValue更新值,但提交时不更新吗? - angular 6 patchValue updates the value but not when I submit? 垫选择组件的角补丁值 - Angular patchValue of a mat-select component Angular 反应形式 patchValue 或 setValue 不起作用 - Angular 10 - Angular reactive forms patchValue or setValue not working - Angular 10 遍历FormGroup控件时的Angular2 patchValue - Angular2 patchValue While Traversing Through FormGroup Controls Angular FormGroup不会在patchValue或setValue之后立即更新其值 - Angular FormGroup won't update it's value immediately after patchValue or setValue 以反应形式将 firebase.firestore.timestamp 转换为 patchValue 之前的日期 - Convert firebase.firestore.timestamp to date before patchValue of data in a reactive form Angular、NgRx:FormControl patchValue() 失败并显示“无法分配给只读属性‘_pendingValue’” - Angular, NgRx: FormControl patchValue() fails with "Cannot assign to read only property '_pendingValue'"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM