1. Anuncie Aqui ! Entre em contato 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 às 20:13.

  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