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
onDocument
: Registration failed for typea-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!
source to share
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"
],
-
Download vise from https://github.com/devpaul/aframe-typings/blob/master/src/AFRAME.d.ts .
-
Referencing typing in your component with:
/// <reference path="../typings/AFRAME.d.ts" />
or set typing globally in tsconfig.json:
"files": [
"typings/AFRAME.d.ts"
]
source to share