1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Angular Form reset value and set all its initial value rather than null

Discussão em 'Angular' iniciado por davecar21, Outubro 5, 2024.

  1. davecar21

    davecar21 Guest

    For example I have a form below.

    searchForm = new FormGroup({
    firstName: new FormControl(''),
    lastName: new FormControl('')
    })

    The problem is that when I use searchForm.reset() the initial value is set to null and not to empty string '' that I set as an initial value in the FormControl.

    I have tried doing the code below and it works. The problem is that for example I have like 20 FormControl, I will need to type it all and initialize it in .reset({firstName:'', other20properties..})


    this.searchForm.reset(
    {
    firstName: '',
    lastName: ''
    }
    );

    Is there a way to reset the form and set all its initial value to empty string ''.

    Continue reading...

Compartilhe esta Página