question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parent function cannot be invoked by child component

See original GitHub issue

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"));
    }
  }
});

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:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
maiahcommented, Jul 19, 2017

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.

1reaction
maiahcommented, Jun 27, 2017

Oh nice! Glad to hear that Moon will have its official state manager. I will keep an eye on this.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found