Parent function cannot be invoked by child component
See original GitHub issuehtml
<script src="https://unpkg.com/moonjs"></script>
<div id="app">
<my-component content="{{parentMsg}}" check="{{talk}}"></my-component>
</div>
JavaScript
Moon.component('my-component', {
props: ['content', 'check'],
template: "<div><p>Data from Parent: {{content}}</p><button m-on:click='say'>SAY</button></div>",
methods: {
say: function() {
this.callMethod("check");
}
}
});
const app = new Moon({
el: "#app",
data: {
parentMsg: "yo"
},
methods: {
talk: function() {
alert("from parent " + this.get("parentMsg"));
}
}
});
html
<script src="https://unpkg.com/moonjs"></script>
<div id="app">
<my-component content="{{parentMsg}}" check="{{talk}}"></my-component>
</div>
JavaScript
Moon.component('my-component', {
props: ['content', 'check'],
template: "<div><p>Data from Parent: {{content}}</p><button m-on:click='say'>SAY</button></div>",
methods: {
say: function() {
this.callMethod("check");
}
}
});
const app = new Moon({
el: "#app",
data: {
parentMsg: "yo"
},
methods: {
talk: function() {
alert("from parent " + this.get("parentMsg"));
}
}
});
This alert()
dialog is not shown when the user clicks SAY button. Or maybe I’m doing it the wrong way? How can the child component call a function from its parent? I supposed to do it via passing the parent’s function thru props. But it doesn’t work.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
parent function not invoked when called from child component ...
I have a parent and a child component and i want to invoke the parent component's function from the child. I have written...
Read more >Call parent component method from a child component in React
In this tutorial, we are going to learn about how to call a parent component method from the child component in React.
Read more >How to call parent Lightning component's method in child ...
Unfortunately methods of a parent component cannot be called from a child component, it works the other way around.
Read more >ReactJS Call Parent Function from Child Component - YouTube
ReactJS call a parent function from a child component using props.
Read more >call child component method from parent react
You need to make use of refs to call a function in the child component from the parent component, and then access the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s still work in progress hack&slash stuff in Gopherjs, I will still need to create a full blown small app on it like todo list or something to see if it works well.
Oh nice! Glad to hear that Moon will have its official state manager. I will keep an eye on this.