我是一個完整的web開發新手,我完全失去了。集成Angular和X3D(渲染一個簡單的框)
我已經下載了Angular教程中使用的Angular Quickstart(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.任何幫助解決這個問題,將不勝感激,謝謝。
要允許Angular呈現模塊中不存在的元素,您必須傳遞架構以允許自定義元素。從'@ angular/core'導入'CUSTOM_ELEMENTS_SCHEMA'並將其添加到您的Angular模塊的模式數組中。並嘗試在Angular運行之前加載x3d。 –
我試過導入'CUSTOM_ELEMENTS_SCHEMA',但這樣做會導致瀏覽器引發很多錯誤(它會抱怨未知元素引用'x3d','material','appearance' ......)。這就是爲什麼我導入了'NO_ERRORS_SCHEMA'。 – GLR
對不起,我是一個完整的web開發新手。如何讓瀏覽器在運行Angular應用程序之前加載x3d?正如你所建議的那樣,我懷疑這是問題所在。 – GLR