In my application I have one parent component and some child components. Need to implement child parent communication here.
- On click child1Component need to pass some data from child1Component to child2Component.
- Display that data in child2Component.
What I did:-
Emitted values from child1 to parent and tried to bind/pass the same value from parent to child2.
But am not getting the value in ngOnInit of child2 as shown below. Need to display that data in child2.
Also the navigation to child2 is not working always redirecting to login page just after displaying the child2 for 1 or 2 seconds.
Child1: <div (click)="onClickData(data)"></div> @Output() getData = new EventEmitter(); onClickData (data:any) { this.getData.emit(data); } Child2: @Input() clickedItem: any = ''; ngOnInit() { alert(this.clickedItem) } Parent: <app-child1 (getdata)="getDataEvent($event)" > </app-child1> <app-child2 [clickedItem] = "clickedData" > </app-child2> clickedData:any; getDataEvent($event: any) { this.clickedData = $event; this.router.navigate(['child2']) }