Reputation: 8309
I am trying to utilise component
in Angular 1.6 with:
< bindings
instead of =
)& bindings
).What is the best approach for calling functions in the child component from the parent component?
In my scenario, my child component will represent a modal dialog with a showModal()
function. I want to pass in an ID for the item I want to edit (easy enough with a <
input binding) and then call the child component's showModal()
method from the parent component (item list).
Upvotes: 0
Views: 866
Reputation: 26828
Simply add an additional binding to control the visibility of the dialog:.
'visible': '<'
$onChanges(changes) {
if(changes.visible && changes.visible.currentValue) {
this.showDialog();
}
}
Upvotes: 1
Reputation: 876
Hey May be you know already but let me point one more most common thing which is broadcasting event from parent to child this works best.
if you know broadcasting events with data like this
$rootScope.$broadcast('resetDataRange',{id:1});
this you should write into your parent component when you want to call method of the child
In Child
$rootScope.$on("resetIntraDataRange",function(data){
showModal(data.id);
});
this will call when broadcasting event triggered and you will get what you want into child .
100% working solution
Upvotes: 0