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

180
Vistas
how to pass form value to another component in angular

I want to show taxDetailsId in my child component Html page. But when click submit button. After click submit button then shows taxDetailsId in my child component Html page.

Parent Component

export class OnlinePaymentComponent implements OnInit {
      HttpClient: any;
    
      paymentForm: FormGroup = this.formBuilder.group({
        taxDetailsId: ['', [Validators.required]]
      });
    
      constructor(
        private formBuilder: FormBuilder,
        private router: Router,
      ) {}
    
      ngOnInit() {}
    
      submitForm(): void {
        if (!this.paymentForm.valid) {
          this.router.navigate(['/home/online-payment/error']);
          return;
        }
      }
    }

Parent.Component.html

     <form [formGroup]="paymentForm" (ngSubmit)="submitForm()">
                <label>Tax Details Id</label>
                  <input type="text" formControlName="taxDetailsId" placeholder="Tax Details Id" />
 <button>Pay Bill</button>
    <form>

Child Component

export class OnlinePaymentErrorComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }

}

Child.Component.html

  <div>
    <button [routerLink]="['/home/online-payment']" >Back Home</button>
  </div>
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

There are two simple ways:

  1. Using query params (without routerLink).
  2. Using Observables.

Using query params, you can use the router.navigate and pass the params you need (Id) along with the route. eg: this.route.navigate(['yourroute/route', { tId: variableWithId }])

Using Observable, when you click on the button, use the same router navigate without params and pass the required data to an observable. On successful routing to the next page, get the resolved data from the observable.

about 4 years ago · Juan Pablo Isaza Denunciar

0

you can try this pattern this.router.navigate(['/heroes', { id: heroId }]);

https://angular.io/guide/router

about 4 years ago · Juan Pablo Isaza Denunciar

0

you can use angular @Input() decorator for it.

Child Component

import { Component, Input } from '@angular/core'; 
export class ChileComponent {
   @Input() public taxDetailsId: number; 
} 

Child Component HTML

enter code here
 <div>
   {{ taxDetailsId  }}
   <button [routerLink]="['/home/online-payment']" >Back Home</button>
 </div>

Parent Component HTML

<app-child-component [taxDetailsId]="taxDetailsId"> </app-child-component>

https://angular.io/guide/inputs-outputs

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