无法将A框架导入组件-Angular2 [英] Can't import A-frame into component - Angular2
问题描述
我有一个使用 angular-cli
创建的项目,通过在其中安装了
,当我尝试通过 aframe
npm install aframe --save import'aframe';
将其导入组件时,会导致以下错误:
I have a project created with angular-cli
where I have installed aframe
via npm install aframe --save
, and when I try to import it in the component via import 'aframe';
it causes the following error:
无法在
Document $ c上执行
registerElement
$ c>:类型为a节点
的注册失败。
Failed to execute
registerElement
onDocument
: Registration failed for typea-node
. A type with that name is already registered.
在这种情况下,使其工作的唯一方法是将库导入到 index.html
文件的< head>
标记。相反,我想访问 aframe
object3D到修改对象实体,如下所示:
In this case, the only way to make it work is by importing the library in the <head>
tag of the index.html
file. Instead I would like to access aframe
object3D to modify objects entities, as shown here:
AFRAME.registerComponent('foo', {
init: function () {
// Do something
}
});
但不幸的是我无法使其工作。您是否有解决此问题的想法?预先感谢您的答复!
but unluckily I am not able to make it work. Do you have an idea on how to solve this issue? Thanks in advance for your replies!
推荐答案
要使它在Angular2中正常工作,您需要具备以下条件:
Here is what you have to get it properly working in Angular2:
- 编辑您的angular-cli.json并将路径添加到脚本节点:
"scripts": [
"node_modules/aframe/dist/aframe-master.js"
],
-
从< a href = https://github.com/devpaul/aframe-typings/blob/master/src/AFRAME.d.ts rel = nofollow noreferrer> https://github.com/devpaul/aframe-typings /blob/master/src/AFRAME.d.ts 。
通过以下方式引用组件中的类型:
Reference the typings in your component with:
/// <reference path="../typings/AFRAME.d.ts" />
或在tsconfig.json中全局安装类型:
or install the typings globally in your tsconfig.json:
"files": [
"typings/AFRAME.d.ts"
]
这篇关于无法将A框架导入组件-Angular2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!