Angular2 + AFrame:注册组件

Angular2 + AFrame: registerComponent

我的 A-Frame 在我的 Angular2 项目中运行良好,但现在我正在尝试注册第 3 方包。具体来说 "aframe-stereo-component" 我有 npm,但现在我需要执行这段脚本。

<script>
  var AFRAME = require('aframe');
  var stereoComponent = require('aframe-stereo-component').stereo_component;
  var stereocamComponent = require('aframe-stereo-component').stereocam_component;

  AFRAME.registerComponent('stereo', stereoComponent);
  AFRAME.registerComponent('stereocam', stereocamComponent);
</script>

我将它添加到我的 index.html 但是它似乎没有用。这有点让我头疼,我可以使用帮助。支持 Oscarmarinmiro aframe-stereo-component on Git

直接在浏览器中添加 NPM require('foo') 语句是行不通的,该方法需要像 Browserify 或 Webpack 这样的捆绑器。如果您还没有使用模块打包器,我会直接包含一个脚本。

<script src="https://cdn.rawgit.com/oscarmarinmiro/aframe-stereo-component/v0.3.1/dist/aframe-stereo-component.min.js"></script>

如果此脚本包含在 A-Frame 本身之后,它应该 'just work' 而无需您注册任何内容。您可以通过在 JS 控制台中检查 AFRAME.components['stereo'] 来确认这一点。

附带说明,最好不要从以这种方式使用的 URL 中删除 "https://" 或 "http://" 前缀。

src="https://cdn.rawgit.com/oscarmarinmiro/aframe-stereo-com‌​ponent/6db3472a/dist‌​/aframe-stereo-compo‌​nent.min.js" .... 是组件的正确导入。谢谢@Don_McCurdy