目前这是一项不容易的任务。
我尝试使用AngularCli完成它。我使用ng new
创建了一个新项目,并按照以下步骤进行:
ng new kframetest
Install aframe
and aframe-template-component
using:
npm install aframe aframe-template-component --save
Due to both (zone.js and A-frame) catch attributeChangedCallback
you need to load A-frame before zone.js. Then (in polyfills.ts
file) I have added:
import 'aframe';
import 'aframe-template-component';
Just before of import 'zone.js/dist/zone';
Create a simple component using kframe sample as template.
In order to Angular can parse specials html tags like <a-entity>
you have to add a CUSTOM_ELEMENTS_SCHEMA
and NO_ERRORS_SCHEMA
to NgModule
using schemas
property:
schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA]
Run the application.
Put the A-Frame
script
tag in thehead
of the HTML before the scene to ensure everything for A-Frame is properly registered before they are used from HTML.
aframe-master.js:75646 A-Frame Version: 0.5.0 (Date 10-02-2017, Commit #bf8b8f9) aframe-master.js:75647 three Version: ^0.83.0 aframe-master.js:75648 WebVR Polyfill Version: dmarcos/webvr-polyfill#a02a8089b
但是一个大问题是Angular试图解析HTML,但它不理解aframe模板语法,你会收到以下错误:
Unhandled Promise rejection: Template parse errors: Parser Error: Unexpected token
#
at column 6 in[src: #boxesTemplate]
inKFrameTestComponent
</a-assets> <a-entity [ERROR ->]template="src: #boxesTemplate" data-box1color="red" data-box2color="green" data-box3color"): KFrameTestComponent@10:12
Property binding
src
not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the@NgModule.declarations
.</a-assets>
我一直在寻找如何添加html而不经过Angular解析它,但是我没有找到...
我试着将模板添加到index html中,它似乎可以工作,但我理解这并不是你想要的情况。
你可以在这里获取代码:https://gitlab.com/jros/angularcli-kframe
<ng-avoid-angular-parser><a-elements-and-whateveryouwant/></ng-avoid-angular-parser>
这将是一个很好的功能,以允许像 k-frame
这样的框架。如果您决定发起一个功能请求,请让我知道以便投票支持它。 - Javier Rosschemas:[CUSTOM_ELEMENTS_SCHEMA]
添加到你的模块中:http://stackoverflow.com/questions/39428132/ - Wulf
Component attempted to register before AFRAME was available
不是 TypeScript 错误。 这是由该库发出的某些运行时错误。 我看不到该库导出任何东西(package.json
中也没有"main"
属性)。 另外请注意,示例中使用了require('kframe');
。如果您以无效的顺序加载依赖项,我将一点也不感到惊讶。 - Aluan Haddad