我是一个完全的新手在网络开发,我完全失去了。
我已经下载了Angular 教程中使用的Angular 快速入门(https://github.com/angular/quickstart),现在我想插入一个简单的x3d元素。为此,我修改了文件app.module.ts
,app.component.ts
和index.html
。
修改后的文件app.module.ts
为:
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';`
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
schemas: [ NO_ERRORS_SCHEMA ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
我创建的新app.component.ts
是:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `<x3d width='600px' height='400px'>
<scene>
<shape>
<appearance>
<material diffuseColor='1 0 0'></material>
</appearance>
<box></box>
</shape>
</scene>
</x3d>`,
})
export class AppComponent { name = 'Angular'; }
最后,新的index.html
如下所示:
<!DOCTYPE html>
<html>
<head>
<title>Angular QuickStart</title>
<base href="/">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script type='text/javascript' src='http://www.x3dom.org/download/x3dom.js'> </script>
<script src="systemjs.config.js"></script>
<script>
System.import('main.js').catch(function(err){ console.error(err); });
</script>
</head>
<body>
<my-app>Loading AppComponent content here ...</my-app>
</body>
</html>
当我运行$ npm start
时,什么都没有显示,浏览器也没有出现任何错误,我不能弄清楚原因。我正在使用Angular 4。任何解决这个问题的帮助都将不胜感激,谢谢。
2条答案
按热度按时间9fkzdhlc1#
问题是X3D在脚本加载时检查
x3d
元素,因为您加载的是包含x3d元素的Angular组件,所以X3D找不到您的元素。不幸的是X3D没有提供这样的方法来检查DOM中的(新)x3d元素。我看到您使用的是Systemjs,您可以在加载appcomponent的过程中使用它轻松地加载脚本。您必须修改Systemjs的配置文件并在组件中添加import语句以加载X3D库。最佳实践是从节点模块加载库。
$ npm install --save x3dom
Systemjs.config:
要用组件加载库,可以向组件的类添加构造函数,并使用Systemjs调用x3d的importstatement。
App.component
现在每次你引导你的应用时,Systemjs都会尝试导入x3dom库,并且不要忘记删除index.html中的x3dom库的导入,该库会检查
window.x3dom
是否已经存在。ogq8wdun2#
旧线程,但将添加此为任何人在未来:
添加一个带有 *ngIf的父div似乎可以让编译器停止抱怨,我不知道为什么,但它就在那里。它甚至可以是 *ngIf=“true”。
将x3dom的CDN添加到我的index.html并使用这个方法就是我需要做的全部事情。