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

338
Views
Cómo restablecer el componente al estado inicial en Angular 2

Tengo un componente que es un modal que tiene un formulario y algunas otras variables fuera de ese formulario. El componente es algo como esto:

El componente:

 export class PersonComponent implements OnInit { countPerson: number=0; persons: Person [] = []; personForm : FormGroup; ngOnInit(){ this.step1Form= this.fb.group({ firstName: 'Levi', lastName: 'Ackerman' }); } submitPerson(person: Person){ this.persons.push(person); this.incrementPerson(); } incrementPerson(){ this.count++; } }

En la plantilla:

 <div class="modal-dialog"> <div class="modal-content"> <div class="modal-body> <label>First Name</label> <input type="text" formControlName="firstName"> <label>LastName Name</label> <input type="text" formControlName="lastName"> <button type="button" (click)="submitPerson()">Submit</button> </div> <div class="modal-footer"> <button type="button" data-dismiss="modal">Close</button> </div> </div> </div>

Quiero restablecer los controles del formulario a los valores iniciales y también establecer las variables fuera del formulario al valor inicial. Básicamente, quiero que todo el componente vuelva al estado inicial. Quiero que el componente se restablezca al estado inicial una vez cerrado.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Si hay un formulario en su HTML (que no se muestra en el fragmento proporcionado), puede usar el método de reinicio en el formulario: this.yourFormName.reset()

Esto restablece el estado del formulario de nuevo a prístino y sin cambios.

about 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!