1

Is it possible to pass a variable of a component A, in the (onclick) on an element in component B like below ?:

Component B:

<comp-A (click)="NodeClicked({{index}})"> </comp-A>

Where index is a variable of the component A.

EEAH
  • 715
  • 4
  • 17
  • Can you please describe relation between component A and B? Whether there is any parent child relationship or not? It would be nice if you can share complete templates and components which is in your mind. – Ashish Kumar Jaryal Aug 15 '20 at 05:04

1 Answers1

2

If you would like to pass the variable from the child (Comp-A) into the parent component (Comp-B) I would suggest using the Event Emitter. An example can be viewed at the bottom of the page.

When a button is clicked from within the child the event will emit to the parent and you can use that data as desired from there.

Mathem8tic
  • 51
  • 6