Can't import A-frame into component - Angular2

I have a project created with angular-cli

where I installed aframe

via npm install aframe --save

and when I try to import it into a component via import 'aframe';

it throws the following error:

Failed registerElement

on Document

: Registration failed for type a-node

. A type with this name is already registered.

In this case, the only way to do it is to import the library into the <head>

file tag index.html

. Instead, I would like to access the aframe

object3D objects to modify the object objects like below:

AFRAME.registerComponent('foo', {
  init: function () {
    // Do something
  }
});

      

but unfortunately I cannot get it to work. Do you have an idea on how to solve this problem? Thanks in advance for your answers!

+1


source to share


1 answer


Here's what you need to get it working correctly in Angular2:

  • Edit your angular-cli.json and add the path to the node scripts:
"scripts": [
  "node_modules/aframe/dist/aframe-master.js"
],

      

  1. Download vise from https://github.com/devpaul/aframe-typings/blob/master/src/AFRAME.d.ts .

  2. Referencing typing in your component with:



/// <reference path="../typings/AFRAME.d.ts" />

      

or set typing globally in tsconfig.json:

"files": [
    "typings/AFRAME.d.ts"
  ]

      

+3


source







All Articles