0
votes

I have angular application which is having parent component and child component interaction. I need to pass the input data value to child component using click event. it must show when clicking the submit button.

How to use input and output event emitter

https://stackblitz.com/edit/angular-7ojvmd

1
stackblitz.com/edit/angular-6hkdjr , in case you wanna see the changes what i have answered belowfaizan

1 Answers

0
votes

I think the easiet what you can do is as below, have one property bind to child and update that property on click event.

   @Component({
  selector: 'my-app',
  template: `Welcome Parent <br>
          <p>Name: <input type="text" [(ngModel)]="name" > <br></p>
          <p>Mobile: <input type="text" ><br></p>
         <button (click)="updatechild()">Submit</button>
         <preview [param1]="forChild" ></preview>
          <button (click)="add.next(control.value)">Add</button>
                `

})
export class AppComponent  {
  public name:string="";
  forChild:string="";
   updatechild(){
     this.forChild=this.name
   }

}