Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does event handling work #24

Closed
janwirth opened this issue Mar 22, 2017 · 3 comments
Closed

How does event handling work #24

janwirth opened this issue Mar 22, 2017 · 3 comments

Comments

@janwirth
Copy link

First off, thank you for this very cool piece of software!

I am kind of stuck on how I would handle a simple click event with ngVue.
I can not find anything about this in the docs.

How is the data flow from the vue component upwards to the angular controller meant to work?

@nicolaspayot
Copy link
Member

nicolaspayot commented Mar 23, 2017

Well, you can't use Vue events from a Vue component that's within an AngularJS one, because you're in AngularJS context. You have to bind event callbacks as props. Here's an example:

  • hello.controller.js (AngularJS)
class HelloController {
  constructor($scope) {
    this.$scope = $scope;
    this.handleClick = this.handleClick.bind(this);
  }

  handleClick(whateverArg) {
    // Don't forget to use $scope.$apply in case you need to update model data
    this.$scope.$apply(() => { ... });
  }
}
  • hello.html (AngularJS)
<vue-component name="Hello" vprops-on-click="$ctrl.handleClick"></vue-component>
  • Hello.vue
<script>
export default {
  props: {
    onClick: Function
  },
  ...
  methods: {
    whateverMethod() {
      this.onClick(this.whateverArg);
    }
  }
};
</script>

Hope this helps ;-)

@janwirth
Copy link
Author

Thank, I will try it out. If I am successful, I will open a PR to merge this intel into the docs!

@janwirth
Copy link
Author

janwirth commented Mar 23, 2017

Done. Please review PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants