无法将 A-frame 导入组件 - Angular2 [英] Can't import A-frame into component - Angular2
问题描述
我有一个用 angular-cli
创建的项目,我通过 npm install aframe --save
安装了 aframe
,当我尝试通过 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
上执行 registerElement
:a-node
类型的注册失败.已注册具有该名称的类型.
Failed to execute
registerElement
onDocument
: Registration failed for typea-node
. A type with that name is already registered.
在这种情况下,使其工作的唯一方法是在 index.html
文件的 标记中导入库.相反,我想访问
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"
],
通过以下方式引用组件中的类型:
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-frame 导入组件 - Angular2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!