Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
¿Cómo restablecer formgroup en angular?

¿Cómo restablecemos los valores de formulario en angular? Por ejemplo, quiero restablecer los valores de createUserForm pero no debería incluir ni restablecer los datos que he agregado en addControl. Gracias

Probé this.createUserForm.reset(); pero se restableció, incluidos los controles adicionales que agregué y que no quiero. Solo los campos en createUserForm

#Código

 createUserForm = new FormGroup({ emailAddress: new FormControl(), firstName: new FormControl(), lastName: new FormControl(), phoneNumber: new FormControl(), companyName: new FormControl(), title: new FormControl(), roleId: new FormControl(), });

#código 2

 getAssociatedAccount() { this.isInProgress = true; this.userService .getUserProfile(this.authService.authUser.nameid, this.accountId) .pipe(finalize(() => (this.isInProgress = false))) .subscribe({ next: (res: any) => { if (res.isSuccess) { this.associatedAccount = res.data.associatedAccount; this.createUserForm.addControl( 'associatedAccount', new FormControl(this.associatedAccount) ); this.createUserForm.addControl( 'accountId', new FormControl(this.accountId) ); } }, error: (err) => noop, complete: () => noop, }); }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Si ve la documentación aquí, se menciona que puede pasar el valor como argumento ( https://angular.io/api/forms/FormGroup#reset )

Entonces, en su caso, puede hacer algo como esto mientras reinicia:

 this.createUserForm.reset({ emailAddress: '', firstName: '', lastName: '', phoneNumber: '', companyName: '', title: '', roleId: '', associatedAccount: this.associatedAccount, accountId: this.accountId });
over 4 years ago · Santiago Trujillo Report

0

Utilice el método reset() para restablecer angular reactiveForm.

Ejemplo

en su caso, simplemente use este método como se muestra a continuación.

 this.createUserForm.reset();

Más detalles...

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!