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 to use callbacks of converted web components in angular? #183

Open
buxbunny110 opened this issue Jun 21, 2024 · 1 comment
Open

How to use callbacks of converted web components in angular? #183

buxbunny110 opened this issue Jun 21, 2024 · 1 comment

Comments

@buxbunny110
Copy link

I've tried many things, but it's not working. Is it even possible? please at least explain how to do that, I can't seem to find anywhere. I have 'on-expand' prop for example how to bind it to angular handler?

@mchill
Copy link

mchill commented Jul 10, 2024

I managed to get it working. One caveat about your example is that you can't bind a property in Angular that starts with on. You'll have to change the name of your prop.

The trick is to change the R2WC prop type. The function prop should be given the value undefined instead of 'function'. This lets R2WC pass the raw value of the web component property to your React component.

const WebComponent = r2wc(ReactComponent, { props: {
  handleExpand: undefined,
} });

After that, I was able to add a function in my Angular component:

handleExpand = () => {
  console.log('called handleExpand');
};

And bind it in the template:

<my-component [handleExpand]="handleExpand"></my-component>

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