Ad
Exchange Data Between Angular Component And Js Script
I hope my question as not asking before.
I'm working with Angular9 and a JS plugin (A-Frame).
I prepared a script is get data and I want to return this data in my component angular for managing his after.
AFRAME.registerComponent('cursor-listener', {
init: function () {
this.el.addEventListener('click', function (evt) {
console.log('I was clicked at: ', evt.detail.intersection.object);
});
}
});
In the script you see above, the console log returns information that is useful to me. I would like to be able to return them in my angular component to process the information later.
I'm beginner with this framework, so excuse me for my ignorance.
Thank you for your futur response, I waiting to read you.
Ad
Answer
You could use arrow function notation to refer to the class member variables using this
keyword. In a conventional JS function, this
keyword refers to the scope of the function.
intersectionObj: any;
AFRAME.registerComponent('cursor-listener', {
init: () => { // <-- arrow function here
this.el.addEventListener('click', (evt) => { // <-- and here
console.log('I was clicked at: ', evt.detail.intersection.object);
this.intersectionObj = evt.detail.intersection.object;
});
}
});
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad