How to send data on a button click event from parent to child ?
I was sending data from parent to child using a button click event but i unable to send
How to send data on a button click event from parent to child ?
I was sending data from parent to child using a button click event but i unable to send
2
Answers
You can solve this in couple of ways:
@Input() someVariable
in the child component thenthat is good if the data on the click is changing.
subscribe
to it and in order to pass the click you can useobservable
orbehavioralSubject
withnext()
More information on:
data binding
observable
behavioralSubject
Live example
why you need to pass the click event to child component in the first place maybe there is a better way to accomplish what you need.
In Angular, you can send data from a parent component to a child component using property binding:
ParentComponent has a property message that is bound to a message input in the ChildComponent using the square bracket syntax [message]. The ParentComponent also has a sendMessage method that changes the value of message when a button is clicked. The ChildComponent displays the value of message in its template. When the button is clicked, the message value is updated in the ParentComponent and automatically passed down to the ChildComponent through property binding.