Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

311
Visualizações
Telling an Angular Reactive form to repaint?

In this reset password material stepper demo in the first step the email is collected in a emailForm.

When next is clicked the submitEmail function sets the value of the emailControl to the email entered.

This is the code for that:

  submitEmail() {
    if (this.emailForm.valid) {
      const email = this.emailForm.get('email')!.value;
      this.confirmCodeForm.get('email')!.setValue(email);
      console.log('THE EMAIL IS: ', this.confirmCodeForm.get('email').value);
      this.onEmailSubmit.emit(email);
    }
  }

We can see that the control value email does have the email entered set through this logging statement:

this.confirmCodeForm.get('email').value);

However in the second step the form does not repaint, and thus the email field (Which is readonly) does not reflect the email address entered.

How do we tell the confirmCodeForm to repaint after calling setValue on the email control?

I also tried using patchValue like this:

      const email = this.emailForm.get('email')!.value;
      this.confirmCodeForm.patchValue({ email });
      console.log('THE EMAIL IS: ', this.confirmCodeForm.get('email').value);
      this.onEmailSubmit.emit(email);

And the control does have the entered email as its value, but the form does not repaint.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Okay, it was quite hard to read what you wanted to achive here. But I think I got it. You want to take entered email from step 1 and copy it to step 2 into email input and form value. Problem was, that control value was set with .setValue(email) but the html code didn't reflect value change because formControlName wasn't pointing to that.

I changed html for the second step formControlName to email and added this.confirmCodeForm.updateValueAndValidity(); just in case (although last one is not explicitly required).

<mat-form-field>
        <input
          type="email"
          matInput
          placeholder="email"
          formControlName="email"
          readonly
        />
</mat-form-field>

Working example: https://stackblitz.com/edit/angular-ivy-qfeglo?file=src%2Fapp%2Freset-password%2Freset-password.component.ts

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda