简体   繁体   English

带有 angular 的 a 帧点击事件

[英]a-frame click events with angular

I am trying to use a-frame in my existing angular application.我正在尝试在我现有的 angular 应用程序中使用框架。 Everything works well and i can use the a-scene within my angular component.html.一切正常,我可以在我的 angular 组件.html 中使用场景。 However i want to register 'click' events on an a-frame component and call an existing function on my angular component.ts file但是我想在 a-frame 组件上注册“点击”事件并在我的 angular component.ts 文件上调用现有的 function

component.html组件.html

<a-scene cursor="rayOrigin: mouse">
 <video id="videoBunny" preload="auto" src="Start.mp4" autoplay loop="true" crossOrigin="anonymous" muted></video>
   <a-videosphere src="#videoBunny">
       <a-cylinder click-event="event: click" position="1 0 -3" radius="0.1" height="1" color="#FFC65D" shadow></a-cylinder>
   </a-videosphere>
 <a-entity camera look-controls="reverseMouseDrag: true"></a-entity>
</a-scene>

component.ts组件.ts

ngAfterViewInit(): void {
 aframe.registerComponent('click-event', {
  dependencies: ['material'],
  init: function () {
    const data = this.data;
    const el = this.el;
      el.addEventListener(data.event,()=>{
        alert("clicked");
      });
  }
 });
}

testFunction(): void {
  alert("test function -  click");
}

Above code works and everytime i click the element a-cylinder it invokes the alert("clicked");上面的代码有效,每次我点击元素 a-cylinder 它都会调用 alert("clicked");

What i want to acheive is to invoke the testFunction() everytime i click the element a-cyclinder.我想要实现的是每次单击元素 a-cyclinder 时调用 testFunction()。

I have tried many things and was not able to make it working.我已经尝试了很多事情,但无法使其正常工作。 My understading about the anonymous functions and this is very limited.我对匿名函数的理解非常有限。

What is the right way to register my existing functions to the eventListener.将我现有的函数注册到 eventListener 的正确方法是什么?

Maybe I'm missing something.. but why not just use the native click handler on a-cylinder ?也许我错过了一些东西..但为什么不直接在a-cylinder上使用本机click处理程序?

<a-cylinder (click)="testFunction($event)" position="1 0 -3" radius="0.1" height="1" color="#FFC65D" shadow></a-cylinder>


testFunction(event): void {
  alert("test function -  click, event info: ", event);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM