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

197
Vistas
angular forms - accessing nested controls in template

I have a nested control group inside my form and i want to access their form state value (like pristine and valid) to display validation errors dynamically.

The is dynamically built like this

controlMap['password'] = this.password;
controlMap['customData'] = this.formBuilder.group(customDataControlMap);
this.form = new FormGroup(controlMap)

the from obj is like

{
  controls:{
    password:{} 
    --->nested 
    customData:{
       controls:{
          customerId:{}
       }
    }
  }
}

the ngClass in the template it looks quite ugly

[ngClass]="( !form.controls.customData.controls.customerId.valid && !form.controls.customData.controls.customerId.touched && submitted) ? 'invalid' : ''"

and won't work in when i try to build it (ng build --prod)

ERROR in ng:///Users/hanche/Desktop/Development/selfbits/beratergruppe-leistungen-webclient/src/app/pages/clients/client-new/client-new.component.html (6,61): Propert y 'controls' does not exist on type 'AbstractControl'.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

try this

form.get('customData').get('customerId')?.invalid

or

form.get('customData.customerId')

is there a way to avoid function calls in template?

using getter

class YourComponent {
  get dataCustomerId() {
    return this.form.get('customData.customerId');
  }
}

template:

[ngClass]="dataCustomerId?.invalid"

angular forms - accessing nested controls in template

over 4 years ago · Santiago Trujillo 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