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

164
Vistas
Angular 2 Cast FormGroup value to interface

I am trying to cast the content of my FormGroup value into an interface which I want use for posting something to my Web Api.

My interface looks like this:

export interface MoneyItemI {
  Description: string;
  Amount: number;
}

My submit methods looks like this:

onSubmit() {
    let jsonString = JSON.stringify(this.itemForm.value);
    let mi = <MoneyItemI>JSON.parse(jsonString);
}

I can see that I get an object created with JSON.parse but unfortunately it does not look like it an valid MoneyItemI object for me.

Property 'Amount' for example is not a number. It is assigned like a string.

How can I create a valid interface with the value of my FormGroup?

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

0

Does this.itemForm.value have the correct Amount and Description properties before you call JSON.stringify(this.itemForm.value)?

If so, you should be able to just do:

let mi = <MoneyItemI>this.itemForm.value;

about 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