在我的angular2代码中,我想更新表单的值,但我的单击功能不起作用

在我的angular2代码中,我想更新表单的值,但我的单击功能不起作用,angular,angular2-template,angular2-forms,Angular,Angular2 Template,Angular2 Forms,在我的angular2代码中,我想更新表单的值,但我的单击功能不起作用 我的代码是: <div *ngIf="payLoad" class="form-row"> <li (click)="select()">{{payLoad}}</li> </div> 在Angular2中,FormGroups仅通过.value公开其值,不能通过它更新FormGroup的值。 您需要使用.setValuevalue或.patchVal

在我的angular2代码中,我想更新表单的值,但我的单击功能不起作用

我的代码是:

<div *ngIf="payLoad" class="form-row">    
    <li (click)="select()">{{payLoad}}</li>   
</div> 
在Angular2中,FormGroups仅通过.value公开其值,不能通过它更新FormGroup的值。 您需要使用.setValuevalue或.patchValuevalue

Use.setValuevalue如果要使用一个对象设置整个组的值,它必须与FormGroup的架构匹配。 如果要使用与FormGroup架构匹配的部分对象仅设置组值的子集,请使用.patchValuevalue。
欢迎来到StackOverflow。我们在这里尽量保持一些质量。请把这乱七八糟的东西收拾干净。您问题中的代码不可读。请阅读:
select(payLoad) {     
    this.form.value.external_id=payLoad;   
}    

onSubmit()  {
    if (this.form.valid) {
        for(let fm in this.form.value) { 
            if(fm == 'external_id') {
                this.payLoad=this.form.value.external_id;
            }   
            if(fm == 'lastname') {
                this.payLoad1=this.form.value.lastname; 
            }
            if(fm == 'email') { 
                this.payLoad2=this.form.value.email;
            } 
            if(fm == 'gender') { 
                this.payLoad3=this.form.value.gender;
            } 
            if(fm=='brave'){ 
                this.payLoad4=this.form.value.brave;
            }  
            if(fm=='role') { 
                this.payLoad5=this.form.value.role; 
            } 
            if(fm=='status') {
                this.payLoad6=this.form.value.status;           
            }       
        }            
    }     
}