Get the value sent from a first form and show it in another

0

I have my form where I register user data with the first and last name fields and it works perfectly; I also have another form with the same fields so that I receive the data and it also works. Now, in that same form I also have a <h4> tag where I want the data sent ( nombre ) of my first form to appear, but it does not appear. I do not know what I'm missing. I appreciate any help.

I want it to appear here:

<p></p>
<h4></h4>

This is my first registration form: With this code I send my data .. (if it works .. if it sends)

sendUserCliente(id, value) {
  this.authService.getById(id).subscribe(res => {
    this.userGet = res;
    const cliente = new Cliente(value.firstName);
    console.log(cliente);
    this.router.navigateByUrl('/cliente/carga/detalle-de-carga');
  }, err => {
    console.error(err);
  });
}
this.myForm = this.fb.group({
  empresa: [
    null,
    Validators.compose([Validators.required, Validators.minLength(3), Validators.maxLength(40)])
  ],
})  

First form

<form [formGroup]="myForm"   (ngSubmit)="myForm.valid && sendForm(myForm.value)
                    " novalidate class="form-horizontal">  
    <div class="form-group has-feedback">
        <input
              type="text"
              id="firstName"
              class="form-control"
              placeholder="Nombre"
              formControlName="firstName"
        >
    </div>
</form>

Second form

This is my second form where I receive the data of the first form, but in my h4 I do not see the data registered in the first form.

    <form [formGroup]="myForm"   (ngSubmit)="myForm.valid && customerUpdateForm(myForm.value)" novalidate class="signup-ademia-formulario-general">
     <div class="form-group has-feedback">
        <input
              type="text"
              id="firstName"
              class="form-control"
              placeholder="Nombre"
              formControlName="firstName"
        >
    </div>
</form>
<h4 id="firstName"></h4>

With this code I receive the data of the first form

customerUpdateForm(value: Object): void {       

    const user = new User(
        this.myForm.value.email,
        this.myForm.value.password,
        this.myForm.value.firstName,        );

this.myForm = this.fb.group({
            empresa: [null , Validators.compose([Validators.required, Validators.minLength(3), Validators.maxLength(40)])],
        },)  
    }

This is the code that I use for both and it works for me since I register and I receive the data. Now I want the data of firstName to appear in the h4 but it does not appear, I do not know what code I should put.

    
asked by daniel mayuri 21.06.2017 в 15:39
source

1 answer

0

I see some pretty basic errors if you are using angular 2.

To start at your <h4 id="firstName"></h4> You are not indicating anything that angular can interpret as there is a value there. That is, you must pass the value either by ngModule or with the tags {{firstName}}.

On the other hand, it would be nice to specify if the forms are on the same html page or in different components. Since if they are in different components you will need to use @Input and @Output to pass the value.

If you expand a little more the information may be able to help you. A part I would like to see the input text where you say that you have managed to show the value, if possible.

Greetings!

    
answered by 24.07.2017 в 18:16