Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
Value of Reactive Form not being set in view due to FormControlName

I have retrieved data from the database and would like to pre-set an update form with preset values. The values are preset when the FormControlName is not set in the input field the interpolation works. Once FormControlName is added it removes it. I have tried setValue and patchValue none have worked. Any suggestions of why this would be or a potential solution? thanks in advance

        
         ngOnInit() {
             this.currUserId = this.userId$.value;
              this.authService
            .findOne(this.currUserId)
             .pipe(map((user: User) => (this.currentUser = user)))
             .subscribe();
             }
             
            
             

                 <div class="tab-container" *ngIf="currentUser">

                  <form [formGroup]="accountForm" (ngSubmit)="submit()">
                   <ion-card class="personal-form">
                  <h3>Personal Details</h3>
                  <div class="form-input">
                  <label>FirstName</label>
                   <input
                  formControlName="firstName"
                  type="text"
                    value="{{currentUser.firstName }}"
                      />
                   </div>
        
                  <div class="form-input">
                   <label>surname</label>
                   <input
                   formControlName="surname"
                  type="text"
                  value="{{ currentUser.surname }}"
                />
                 </div>
             </form>
         </div>
                            
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Instead of passing value in the input element, use "formBuilder".

constructor(
  ...
  private _fb: FormBuilder,
){}



ngOnInit() {
  this.accountForm = this._fb.group({
      firstName: [''],
      surname: [''],
  });
  this.getCurrentUser();
}

getCurrentUser() {
      this.currUserId = this.userId$.value;
      this.authService
            .findOne(this.currUserId)
            .subscribe((user: User) => {
                 this.currentUser = user;
                 this.accountForm.patchValue(this.currentUser);
       });
  }
}

and remove both value="{{currentUser.firstName }}" form HTML.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda