要更新来自不同表单组的表单组 formcontrol 值,但我不想永久更改值(Angular)

To update a formgroup formcontrol value from different formgroup but I do not to want to change the values permanently(Angular)

将鼠标悬停在 table 的第一列上时,会出现一个工具提示,单击按钮对话框会打开,其中包含编辑 json 部分

我提供了两个功能:-

[请select从对话框左侧开始一行]

1) 可以编辑 json(在这种情况下,用户单击左侧部分的行,开始编辑 json,并且在不还原新更改的情况下,用户单击下方的不同行左侧部分并再次 select 返回先前 select 编辑的行原始 json 数据被保留)

2) 用户单击左侧部分的行,并开始从输入字段(出现在“添加为”按钮上方)输入内容我开始更新编辑 Json 中的 'mTitle' 键section ,所以这里也是一旦用户点击不同的行并再次返回到先前 selected 行 json 'mTitle' 键不显示原始(旧)值

预期行为

我所期望的是,一旦用户输入,'mTitle' 键应该被更新(这是有效的)但是 'mTitle' 键应该在添加后再次保留其旧值当单击“新建”按钮或用户单击其他行时。(与情况 1 中的行为相同)

Stackblitz link https://stackblitz.com/edit/angular-mat-tooltip-v6m2tz?file=app%2Falert-dialog%2Falert-dialog.component.ts

请推荐

警报-dialog.component.html

<form [formGroup]="jsonform">
            <json-input formControlName="json" name="result"></json-input>
</form>

 <form [formGroup]="submitJsonNameAndForm" class="">
    <mat-form-field [floatLabel]="'never'" class="alertinput">
        <input matInput trim type="text" #alertnamefieldRef formControlName="alertnamefield" placeholder="Custom Alert Name"
            autocomplete="off" (keyup) = "passingAlerTitle(alertnamefieldRef?.value)">
    </mat-form-field>
</form>

警报-dialog.component.ts

passingAlerTitle(event){
    this.data.data[this.selectedId].conditionals.alert.mTitle = event;
    this.jsonform.setValue({
      json: this.data.data[this.selectedId].conditionals
     });  
}

我尝试在添加新按钮时实现这个

您只需要保留一份 selected 项目并根据您的情况使用它。

这是stackblitz link

在第 59 行 this.customTitle= _.cloneDeep(this.data.data[this.selectedId]);,当用户 select 来自左侧面板时,在自定义标题

在第 72 行,创建了一个临时变量,它将从 jsonData.

保持变化 object

在第 73 行,使用 customTitle 中的原始数据更新了 json 数据。

在第 74 行,将临时变量(新标题)添加到 json 数据(这是已更新的行,您可以在任何地方使用它)