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

179
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

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

https://angular.io/guide/router

about 4 years ago · Juan Pablo Isaza Relatório

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 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