简体   繁体   中英

how to reset() form to specific value reactively in angular 7

my .ts file to do this is:

 export class AppComponent implements OnInit {
      genders = ['male', 'female'];
      signupForm: FormGroup;


      constructor(private formBuilder: FormBuilder){}


      toSubmit(){
        console.log(this.signupForm); 
        this.signupForm.reset(this.signupForm.controls.userData.value.username = 'ahmad');
        console.log(this.signupForm.controls.userData.value.username);

      };

But it does'nt work and the value of username stay null.

you should use this.signupForm.patchValue({username = 'ahmad'}); instead of reset

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM